jQuery Hover image change animation

后端 未结 7 683
难免孤独
难免孤独 2021-01-03 02:54

I have an IMG tag with a grayscale image. I hooked up a Hover() event in order to change the \"src\" to a color image on hover, and back to grayscale on mouse-out.

7条回答
  •  孤街浪徒
    2021-01-03 03:27

    Where are you fading out ? Fade in does display:block with opacity changing from 0 to 100. Fade out does display:none with opacity changing from 100 to 0.

    Once, you fadeIn, image is display:block and opacity is 100. So, you dont see an animation. So, either do a display:none or fadeOut before fadeIn again.

    Given is example with explains things. You should change it according to your requirements.

    $("#showForm").hover(
                  function () {
                    $(this).fadeOut('fast').fadeIn('slow', function(){
                        $(this).attr("src", 'images/AddButtonSmall.gif');
                    });
                  }, 
                  function () {
                    $(this).fadeOut('fast').fadeIn('slow', function(){
                        $(this).attr("src", 'images/AddButtonSmallGray.gif');
                    });
                  }
                );
    

提交回复
热议问题