Loading... <p><img src="https://www.xxhzm.cn/usr/uploads/2021/09/2570018716.gif" alt="20210928170939.gif" title="20210928170939.gif"style=""></p><p><!doctype html></p><pre><code><html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style> * { margin: 0; padding: 0 } .aa { width: 990px; height: 360px; border: 3px #F00 solid; margin: 100px auto; position: relative; overflow: hidden; } .aa .pic li { width: 990px; height: 360px; list-style: none; float: left } .aa .pic li img { width: 990px; height: 360px; } .aa .list { width: 200px; height: 40px; position: absolute; right: 100px; bottom: 20px } .aa .list li { width: 25px; height: 25px; list-style: none; float: left; text-align: center; line-height: 25px; background: #FCB400; border-radius: 50%; margin: 5px; cursor: pointer } .aa .list li.on { background: #C50A0E; color: #FFF } </style> <script src="https://www.xxhzm.cn/jq.js"></script> <script> $(function() { let w = $('.aa .pic li').width() let n = $('.aa .pic li').length $('.aa .pic ul').width(n * w) let btn = '<ul>' for (let i = 0; i < n; i++) { btn = btn + '<li>' + (i + 1) + '</li>' } btn = btn + '</ul>' $(btn).appendTo($('.list')).find('li').first().addClass('on') function move() { let i = $('.aa .list li').index($('.aa .list li.on')) if (i == n - 1) { i = 0 } else { i = i + 1 //下一个 } $('.aa .list li').eq(i).addClass('on').siblings().removeClass('on') $('.aa .pic li').hide().eq(i).fadeIn(500) } timer = setInterval(move, 2000) $('.aa .list li').click(function() { let i = $('.aa .list li').index(this) $('.aa .pic li').hide().eq(i).fadeIn(500) $(this).addClass('on').siblings('li').removeClass('on') }) $('.aa').mouseenter(function() { clearInterval(timer) }) $('.aa').mouseleave(function() { timer = setInterval(move, 2000) }) }) </script> </head> <body> <div class="aa"> <div class="pic"> <ul> <li><img src="1.jpg"></li> <li><img src="2.jpg"></li> <li><img src="3.jpg"></li> <li><img src="4.jpg"></li> </ul> </div> <div class="list"></div> </div> </body> </html> </code></pre> 猜你想看 开学啦 nuxt3目录结构详解 发现未知可能性!小小API引领你的创新之旅! 每日一学:PHP 中的array_replace_recursive函数详解 cdn.xxhzm.cn免费的静态文件加速服务 求助帖!关于axios跨域的问题 - 已解决 JS代码防止网站别别人恶意镜像 JavaScript实现猜数字小游戏 Vue组件的使用 react学习-JSX(二) 最后修改:2022 年 06 月 05 日 © 允许规范转载 赞 0 如果觉得我的文章对你有用,请随意赞赏