you could test if the gif element you want to animate is visible on the screen (depending on screen scroll)
Here is a stackoverflow post that show a function to detect if an element is visible on screen :
Check if element is visible after scrolling
Here is the code :
function isScrolledIntoView(elem)
{
var $elem = $(elem);
var $window = $(window);
var docViewTop = $window.scrollTop();
var docViewBottom = docViewTop + $window.height();
var elemTop = $elem.offset().top;
var elemBottom = elemTop + $elem.height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
After that, you could listen on scroll event and if the element is visible, just animate it.
Hope that helped, good luck mate