Onclick play GIF image with jQuery and start from beginning

后端 未结 2 1499
我在风中等你
我在风中等你 2021-01-06 10:52

I have a website with images on it. Some of the images are animated GIF images. What I\'ve done is to show a static image of the GIF and on a click event, the actual GIF ima

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 11:28

    this would be a solution to larger images Restart an animated GIF from JavaScript without reloading the image

    in a nut shell load the image into a javascript variable then change out the src on click

    $(function(){
        var image = new Image();
           image.src='http://rack.3.mshcdn.com/media/ZgkyMDEyLzEwLzE5LzExXzMzXzMzXzE3Nl9maWxlCnAJdGh1bWIJMTIwMHg    5NjAwPg/462b8072';
         $('#img').click(function(){
           $(this).attr('src',image.src);
         }); 
     });
    

    http://jsfiddle.net/GS427/1/

    its ugly i couldnt find the right image for the starting but you can see that it starts in the same place every time

提交回复
热议问题