分类 前端 下的文章

鼠标经过切换图片(js特效基础)

code:https://github.com/net-web/javasript-base.git
代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<img src="images/1.jpg" alt="" id="img"/>
<script>
    var pic = document.getElementById("img");//获取DOM
    pic.onmouseover = function () {
        pic.src = "images/2.jpg";
    }
    pic.onmouseout = function () {
        pic.src = "images/1.jpg";
    }
</script>
</body>
</html>

效果:
GIF.gif