Last active
March 11, 2019 18:43
-
-
Save coclav/5760690 to your computer and use it in GitHub Desktop.
Start the animation of a .gif on click. This adds a "start / stop" button below your still image (abc_still.gif / class : img_anim) that will change the .gif to the animated version (abc.gif)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(".img_anim").after( function() { | |
// keep ref to the image | |
var image = this; | |
// add div container for the link | |
var $d = jQuery("<div />"); | |
// add link | |
var $a = jQuery("<a>Start / Stop animation</a>"); | |
$d.append($a); | |
// add click event | |
$a.on("click", function() { | |
// get the src of the image | |
var src = jQuery(image).attr("src"); | |
// change the image | |
if(jQuery(src.split("_")).last()[0] == "still.gif") | |
jQuery(image).attr('src', src.replace('_still.gif', '.gif')); | |
else | |
jQuery(image).attr('src', src.replace('.gif', '_still.gif')); | |
}) | |
return $d; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment