首页 > Web开发 > 详细

17 JS-图片切换PLUS&关闭小广告

时间:2019-07-04 00:20:13      阅读:122      评论:0      收藏:0      [点我收藏+]

图片切换PLUS

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>05 图片切换PLUS</title>
 6     <style type="text/css">
 7         *{
 8             padding: 0;
 9             margin: 0;
10         }
11         #box{
12             border: 1px solid #ccc;
13             width: 430px;
14             height: 70px;
15             padding-top: 430px;
16             background: url(‘images/big_pic1.jpg‘) no-repeat;
17         }
18         #box ul li{
19             display: inline-block;
20             margin-right: 15px;
21         }
22     </style>
23 </head>
24 <body>
25     <div id="box">
26         <ul>
27             <li class="item">
28                 <img src="images/pic1.jpg">
29             </li>
30             <li class="item">
31                 <img src="images/pic2.jpg">
32             </li>
33             <li class="item">
34                 <img src="images/pic3.jpg">
35             </li>
36             <li class="item">
37                 <img src="images/pic4.jpg">
38             </li>
39             <li class="item">
40                 <img src="images/pic5.jpg">
41             </li>
42         </ul>
43     </div>
44     <script type="text/javascript">
45         // 1.获取事件源
46         function $(id){
47             return typeof id === string ? document.getElementById(id) : null;
48         }
49         var items = document.getElementsByClassName(item);
50         for(var i = 0;i < items.length; i++){
51             var item  = items[i];
52             item.index = i+1; //  记录每一个item的index,切换图片时调用
53             items[i].onmouseover = function(){
54                 $(box).style.background = ` url(images/big_pic${this.index}.jpg) no-repeat`;
55             }
56         }
57     </script>
58 
59 </body>
60 </html>

 

关闭小广告

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>关闭小广告</title>
    <style type="text/css">
        *{
            padding: 0;
            margin: 0;
        }
        #qe_code{
            width: 180px;
            height: 160px;
            margin: 100px auto;
            position: relative;
        }
        #qe_code img{
            position: absolute;
            right: 0;
        }
        #qe_code #close{
            position: absolute;
            width: 18px;
            height: 18px;
            border: 1px solid #e0e0e0;
            text-align: center;
            line-height: 18px;
            cursor: pointer;
            color: #666;
        }
    </style>
</head>
<body>
    <div id="qe_code">
        <img src="images/phone_taobao.png" id="code">
        <span id="close">X</span>
    </div>
</body>
    <script type="text/javascript">
        window.onload = function () {
            var close = document.getElementById(close);
            var qe_code = document.getElementById(qe_code);
            close.onclick = function () {
                qe_code.parentNode.removeChild(qe_code);
            }
        }
    </script>
</html>

 

17 JS-图片切换PLUS&关闭小广告

原文:https://www.cnblogs.com/znyyy/p/11129808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!