Change the image source on rollover using jQuery

前端 未结 14 1036
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 10:23

I have a few images and their rollover images. Using jQuery, I want to show/hide the rollover image when the onmousemove/onmouseout event happen. All my image names follow t

14条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 10:43

    If you have more than one image and you need something generic that doesn't depend on a naming convention.

    HTML

    
    
    
    

    JavaScript

    $('img').bind('mouseenter mouseleave', function() {
        $(this).attr({
            src: $(this).attr('data-other-src') 
            , 'data-other-src': $(this).attr('src') 
        })
    });
    

提交回复
热议问题