您当前的位置: 首页 > 

暂无认证

  • 3浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

dom啦15 商品展示

发布时间:2020-09-06 19:48:12 ,浏览量:3

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>15-JavaScript-商品展示</title> <style> *{ margin: 0; padding: 0; } div{ width: 430px; margin: 100px auto; border: 1px solid #000; } ul{ list-style: none; display: flex; justify-content: space-between; } ul>li>img{ width: 80px; height: 80px; vertical-align: bottom; } ul>li{ border: 2px solid transparent; box-sizing: border-box; } .current{ border: 2px solid skyblue; } </style> </head> <body> <div> <img src="images/pic1.jpg" alt=""> <ul> <li><img src="images/pic1.jpg" alt=""></li> <li><img src="images/pic2.jpg" alt=""></li> <li><img src="images/pic3.jpg" alt=""></li> <li><img src="images/pic4.jpg" alt=""></li> <li><img src="images/pic5.jpg" alt=""></li> </ul> </div> <script> // 1.拿到需要操作的元素 let oImg = document.querySelector("div>img"); let oItems = document.querySelectorAll("li>img"); // 2.给每一个小图添加移入和移出事件 for(let item of oItems){ // 监听移入事件 item.onmouseenter = function () { // 1.给当前小图的父元素添加边框 this.parentNode.className = "current"; // 2.将当前小图的图片地址设置给大图 oImg.src = this.src; } // 监听移出事件 item.onmouseleave = function () { // 1.移除当前小图父元素的边框 this.parentNode.className = ""; } } </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0846s