jQuery - Change image src on hover

前端 未结 6 963
自闭症患者
自闭症患者 2020-12-10 14:28

Basically I want to change the image src to add -active.png on hover.

So fb.png would become fb-active.png on hover, and fb.png when it\'s not hovering.

6条回答
  •  -上瘾入骨i
    2020-12-10 15:04

    I use this script.. base on the script above... it just switch between the active and original image.

    $("document").ready(function(){ 
            $(".my_image").mouseenter(function(){       
                $(this).attr('src',function(index, attr){
            return attr.replace(".png", "-active.png");
        });      
            });     
            $(".my_image").mouseleave(function(){       
                $(this).attr('src',function(index, attr){
            return attr.replace("-active.png",".png");});      
            }); 
        });
    

提交回复
热议问题