js基础 仿 百度换皮肤 案例


 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        ul{
            width: 800px;
            position: absolute;
            top: 200px;
            left: 500px;

        }
        ul img{
            float: left;
            border: 1px solid #333;
            width: 200px;
            box-sizing: border-box;
        }
    </style>
</head>
<body>
    <ul>
        <li><img src="./images/1.jpg" alt=""></li>
        <li><img src="./images/2.jpg" alt=""></li>
        <li><img src="./images/3.jpg" alt=""></li>
        <li><img src="./images/4.jpg" alt=""></li>
    </ul>
    <script>
        // 获取元素
        var bodyEle = document.body;
        var img     = document.getElementsByTagName('img');
        // 绑定事件
        for(var i=0;i<img.length;i++){
            img[i].onclick = function(){
        // 背景颜色替换
                bodyEle.style.background = "url("+this.src+") no-repeat";
            }
        }
    </script>
</body>
</html>

 js基础  仿 百度换皮肤 案例js基础  仿 百度换皮肤 案例js基础  仿 百度换皮肤 案例js基础  仿 百度换皮肤 案例

 

上一篇:CSDN的代码片段复制不了解决方案


下一篇:Javascript实现让图片一直跟着鼠标移动