Animating a gif on hover

后端 未结 3 1807
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 11:44

I\'ve looked for the answer for this and I found it, but I don\'t know how to use it.

Stop a gif animation onload, on mouseover start the activation

Guffa\'s

3条回答
  •  悲&欢浪女
    2020-12-05 12:05

    I haven't read the link, however the easiest way to do this is to change the img tags src attribute with javascript on hover like this (jQuery)

    $(function() {
        $('a').hover(function() {
          $(this).attr('src','path_to_animated.gif');
        },function() {
          $(this).attr('src','path_to_still.gif');
        }
    });
    

    No plugins required... you might want to preload the animated gif by adding $('',{ src: 'path_to_animated.gif'}); before the hover bind.

    Hope that helps

提交回复
热议问题