Loading... <p>鼠标离开时向左或者是向右移动使用的是i可以会有bug。<br>如有更好的方法可以在下方评论区提出。<br><img src="https://www.xxhzm.cn/usr/uploads/2021/09/2457084588.gif" alt="20210923163515.gif" title="20210923163515.gif"style=""><br><div class="panel panel-default collapse-panel box-shadow-wrap-lg"><div class="panel-heading panel-collapse" data-toggle="collapse" data-target="#collapse-600601e44e6f4ad95e59f1ee8a7dace161" aria-expanded="true"><div class="accordion-toggle"><span style="">代码</span> <i class="pull-right fontello icon-fw fontello-angle-right"></i> </div> </div> <div class="panel-body collapse-panel-body"> <div id="collapse-600601e44e6f4ad95e59f1ee8a7dace161" class="collapse in collapse-content"><p></p></p><pre><code><!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; } .cont { width: 400px; height: 200px; background: turquoise; margin: 200px auto; position: relative; overflow: hidden; } span { display: block; font-size: 30px; color: #fff; position: absolute; cursor: pointer } #zuo { top: 40%; left: 10px; } #you { top: 40%; right: 10px; } .cont ul { position: absolute } .cont ul li { list-style: none; float: left; } .cont ul li img { width: 400px; height: 200px; } </style> <script src="https://www.xxhzm.cn/jq.js"></script> <script> $(function() { $('ul').width($('li').length * $('li').width()); //设置ul的宽度 let timer = null //重置定时器 $('span').hide() //两个侧边的小按钮关闭 i = 0; //离开时播放什么动画 function left() { //向左移动 clearInterval(timer) timer = setInterval(() => { $('ul').animate({ 'left': -$('li').width(), }, 1000, function() { $('li').first('li').appendTo('ul') $(this).css('left', '0') }) }, 2500); } function right() { //向右移动 clearInterval(timer) timer = setInterval(() => { $('ul').css('left', -$('li').width()) $('li').last('li').prependTo('ul') $('ul').animate({ 'left': '0px' }, 1000) }, 2500); } left() $('.cont').mouseenter(function() { i = 0 clearInterval(timer) $('span').show(500) }) $('.cont').mouseleave(function() { $('span').hide() if (i == 0) { left() } }) $('#you').click(function() { i++ right() }) $('#zuo').click(function() { i++ left() }) }) </script> </head> <body> <div class="cont"> <ul> <li><img src="theme1.png"></li> <li><img src="theme2.png"></li> <li><img src="theme3.png"></li> <li><img src="theme4.png"></li> </ul> <span id="zuo">&lt;</span> <span id="you">&gt;</span> </div> </body> </html> </code></pre><p><p></p></div></div></div></p> 猜你想看 Vue生命周期 每日一学:PHP 中的array_uintersect_uassoc函数详解 每日一学:PHP 中的array_udiff函数详解 nuxt3状态管理 TS自动运行+Parcel打包 Vue组件的使用 go语言切片 JS代码防止网站别别人恶意镜像 vue2使用ajax发送网络请求 HTTP请求状态码大全 最后修改:2022 年 06 月 05 日 © 允许规范转载 赞 0 如果觉得我的文章对你有用,请随意赞赏
1 条评论
非常棒非常棒 真好使啊