I've seen a lot of answers to this question using jQuery. Like this: Stop a gif animation onload, on mouseover start the activation and Animating a gif on hover. But I'm looking for a way to do it with angular. I'm thinking it should be the same idea as when doing it in jQuery. I want to do exactly what the person who asked the question in the first link wanted to do, but in angular:
On page load => Animations for all gifs are stopped
On mouseover => Animations starts for that one gif
On mouseout => Animation stops again for that gif
Here's what I have in my HTML:
<img class="projectGif" src="{{project.gifUrl}}" ng-mouseover="animation(project)">
The "project" object that I'm passing into the animation function is an object I'm getting earlier in my code from ng-repeat="project in projects". Then in my JavaScript:
$scope.animation = function(project) {
//not sure what to do here
};
I looked around on the angular documentation page for something similar to the jQuery $(this).attr()
, and found stuff like $attr, and $set, and I thought maybe I could just use those to set the src in my img tag to the pathway for my img. So like $set('src', 'project.imgUrl')
but I get an error in my console that says $set is not defined
.
So my main question is, how do I use angular to make it so that my web page starts with a static .gif (or img etc) and then on hover, have the static .gif change to an animated .gif?