I am working for a designer who has created a GIF that only has one cycle of an animation. This gif actually appears about halfway down a scrolling page, i.e it starts off screen, so by the time you get there the animation has already fired.
I have created two versions of this GIF, one in it starting state, and the animated one.
I want it so that when the user scroll down the page, the animated GIF loads at the appropriate time (i,e when its on screen), and then loads the animated version into the DOM which then plays
I have tried using scrollspy, but this only delays the showing of the icon, and not the actual loading, so when it appears as the user scrolls down the animation has already been and gone.
Is it possible? My common sense is telling me that this is not even worth the dev time as its not even that important an animation, and should just be on a loop like most normal GIF's but.. well.. thats designers for ya!
- Static version = step_4.gif
- Animated version = step_4_b.gif
All encapsulated in a
Thanks in advance for any assiatance
NOTE : Using the answer below, this was my working piece of code (needs tidying, and the plugin was installed)
jQuery(document).ready(function($) {
window.onscroll = function() {
if($("#printer_animated_image").visible()) { //this determines if the element is visible
$("#printer_animated_image").attr("src", "images/modules/how_it_works/step_4_b.gif"); //this sets the image source
}
}
});
</script>