| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- *{
- margin: 0;
- padding: 0;
- }
- li{
- list-style: none;
- }
- .clearfix::after{
- content: "";
- display: block;
- clear: both;
- }
- .content{
- width: 500px;
- border:2px solid #999;
- margin:100px auto;
- text-align: center;
- }
- .big-img img{
- width: 400px;
- height: 300px;
- }
- .small-img{
- border-top:2px solid #999;
- }
- .small-img img{
- width: 100px;
- height: 80px;
- }
- .small-img ul li{
- float: left;
- border-right: 2px solid #999;
- width: 125px;
- box-sizing: border-box;
- text-align: center;
- }
- .small-img ul li:last-child{
- border-right: 0;
- }
- </style>
- </head>
- <body>
- <div class="content">
- <div class="big-img">
- <img id="bigImg" src="./img/phone.png" alt="phone">
- </div>
- <div class="small-img">
- <ul class="clearfix">
- <li><img src="./img/phone.png" alt="phone"></li>
- <li><img src="./img/phone2.png" alt="phone2"></li>
- <li><img src="./img/ad1.jpg" alt="ad1"></li>
- <li><img src="./img/ad2.png" alt="ad2"></li>
- </ul>
- </div>
- </div>
- <script>
- // 获取元素
- var bigImg = document.getElementById("bigImg");
- // var smallImgs = document.getElementsByClassName("small-img")[0].getElementsByTagName("img");
- var smallImgs = document.querySelectorAll(".small-img img");
- // smallImgs[0].onmouseover = function(){
- // var thisSrc = smallImgs[0].getAttribute("src");
- // bigImg.setAttribute("src",thisSrc);
- // }
- // smallImgs[1].onmouseover = function(){
- // var thisSrc = smallImgs[1].getAttribute("src");
- // bigImg.setAttribute("src",thisSrc);
- // }
- // smallImgs[2].onmouseover = function(){
- // var thisSrc = smallImgs[2].getAttribute("src");
- // bigImg.setAttribute("src",thisSrc);
- // }
- // smallImgs[3].onmouseover = function(){
- // var thisSrc = smallImgs[3].getAttribute("src");
- // bigImg.setAttribute("src",thisSrc);
- // }
- // 循环遍历smallImgs数组
- for(var i=0;i<smallImgs.length;i++){
- smallImgs[i].onmouseover = function(){
- // console.log("鼠标移入");
- console.log(i);
- // var thisSrc = smallImgs[i].getAttribute("src");
- var thisSrc = this.getAttribute("src");
- bigImg.setAttribute("src",thisSrc);
- }
- }
- </script>
- </body>
- </html>
|