jQuery - Change image src on hover

前端 未结 6 993
自闭症患者
自闭症患者 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条回答
  •  长情又很酷
    2020-12-10 15:19

    This can be done without javascript, with only css. Like this:

    Give different classes for icons like fb for facebook,tw or twitter and so on.

    HTML:

    CSS:

    .img-social{display:inline-block;height:20px;width:20px;}
    .fb{background:url("images/fb.png");}
    .fb:hover{background:url("images/fb-active.png");}
    .tw{background:url("images/twitter.png");}
    .tw:hover{background:url("images/twitter-active.png");}
    .ln{background:url("images/linkedin.png");}
    .ln:hover{background:url("images/linkedin-active.png");}
    .wp{background:url("images/wordpress.png");}
    .wp:hover{background:url("images/wordpress-active.png");}
    

    You can use sprite for efficiency.

提交回复
热议问题