欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

【常见】移动端实例——图片无缝滚动

程序员文章站 2022-03-23 19:07:39
Document</t ......</div> <div class="content"> <p><span style="font-size: 14pt"><!doctype html></span><br><span style="font-size: 14pt"><html lang="en"></span><br><span style="font-size: 14pt"><head></span><br><span style="font-size: 14pt"> <meta charset="utf-8" /></span><br><span style="font-size: 14pt"> <meta name="viewport" content="width=device-width,user-scalable=no"></span><br><span style="font-size: 14pt"> <title>document</title></span><br><span style="font-size: 14pt"> <script type="text/javascript"></span><br><span style="font-size: 14pt"> //获取html</span><br><span style="font-size: 14pt"> var html = document.documentelement;</span><br><span style="font-size: 14pt"> //设置html的字体大小 = 可视区的宽度 / 15</span><br><span style="font-size: 14pt"> html.style.fontsize = html.clientwidth / 15 + 'px';</span><br><span style="font-size: 14pt"> //阻止pc和浏览器默认行为。</span><br><span style="font-size: 14pt"> document.addeventlistener('touchstart',function(ev){</span><br><span style="font-size: 14pt"> ev.preventdefault();</span><br><span style="font-size: 14pt"> });</span><br><span style="font-size: 14pt"> </script></span><br><span style="font-size: 14pt"><style></span><br><span style="font-size: 14pt">body{</span><br><span style="font-size: 14pt"> margin: 0;</span><br><span style="font-size: 14pt">}</span><br><span style="font-size: 14pt">.wrap{</span><br><span style="font-size: 14pt"> height: 4.68rem;</span><br><span style="font-size: 14pt"> position: relative;</span><br><span style="font-size: 14pt">}</span><br><span style="font-size: 14pt">.list{</span><br><span style="font-size: 14pt"> padding: 0;</span><br><span style="font-size: 14pt"> margin: 0;</span><br><span style="font-size: 14pt"> width:400%;</span><br><span style="font-size: 14pt"> position: absolute;</span><br><span style="font-size: 14pt"> top:0;</span><br><span style="font-size: 14pt"> left:0;</span><br><span style="font-size: 14pt"> list-style: none;</span><br><span style="font-size: 14pt">}</span><br><span style="font-size: 14pt">.list li{</span><br><span style="font-size: 14pt"> float: left;</span><br><span style="font-size: 14pt"> width:15rem;</span><br><span style="font-size: 14pt">}</span><br><span style="font-size: 14pt">.list img{</span><br><span style="font-size: 14pt"> width:15rem;</span><br><span style="font-size: 14pt"> display: block;</span><br><span style="font-size: 14pt">}</span><br><span style="font-size: 14pt">nav{</span><br><span style="font-size: 14pt"> width:15rem;</span><br><span style="font-size: 14pt"> height: 10px;</span><br><span style="font-size: 14pt"> position: absolute;</span><br><span style="font-size: 14pt"> bottom:5px;</span><br><span style="font-size: 14pt"> z-index: 1;</span><br><span style="font-size: 14pt"> text-align:center;</span><br><span style="font-size: 14pt">}</span><br><span style="font-size: 14pt">nav a{</span><br><span style="font-size: 14pt"> width:15px;</span><br><span style="font-size: 14pt"> height: 15px;</span><br><span style="font-size: 14pt"> display: inline-block;</span><br><span style="font-size: 14pt"> background: red;</span><br><span style="font-size: 14pt"> border-radius:50%;</span><br><span style="font-size: 14pt"> vertical-align:top;</span><br><span style="font-size: 14pt">}</span><br><span style="font-size: 14pt">nav a.active{</span><br><span style="font-size: 14pt"> background:#fff;</span><br><span style="font-size: 14pt">}</span><br><span style="font-size: 14pt"></style></span><br><span style="font-size: 14pt"></head></span><br><span style="font-size: 14pt"><body></span><br><span style="font-size: 14pt"> <section class="wrap"></span><br><span style="font-size: 14pt"> <ul class="list"></span><br><span style="font-size: 14pt"> <li></span><br><span style="font-size: 14pt"> <img src="img/img.jpg" alt="" /></span><br><span style="font-size: 14pt"> </li></span><br><span style="font-size: 14pt"> <li></span><br><span style="font-size: 14pt"> <img src="img/img2.jpg" alt="" /></span><br><span style="font-size: 14pt"> </li></span><br><span style="font-size: 14pt"> <li></span><br><span style="font-size: 14pt"> <img src="img/img3.jpg" alt="" /></span><br><span style="font-size: 14pt"> </li></span><br><span style="font-size: 14pt"> <li></span><br><span style="font-size: 14pt"> <img src="img/img4.jpg" alt="" /></span><br><span style="font-size: 14pt"> </li></span><br><span style="font-size: 14pt"> </ul></span><br><span style="font-size: 14pt"> <nav></span><br><span style="font-size: 14pt"> <a href="javascript:;" class="active"></a></span><br><span style="font-size: 14pt"> <a href="javascript:;"></a></span><br><span style="font-size: 14pt"> <a href="javascript:;"></a></span><br><span style="font-size: 14pt"> <a href="javascript:;"></a></span><br><span style="font-size: 14pt"> </nav></span><br><span style="font-size: 14pt"> </section></span><br><span style="font-size: 14pt"> <script type="text/javascript"></span><br><span style="font-size: 14pt"> var wrap=document.getelementsbyclassname("wrap")[0],</span><br><span style="font-size: 14pt"> list=document.getelementsbyclassname("list")[0],</span><br><span style="font-size: 14pt"> disx=0,</span><br><span style="font-size: 14pt"> listl=0,</span><br><span style="font-size: 14pt"> n=0,</span><br><span style="font-size: 14pt"> w=wrap.clientwidth,</span><br><span style="font-size: 14pt"> s=0,</span><br><span style="font-size: 14pt"> timer=0;</span><br><span style="font-size: 14pt"> a=document.getelementsbytagname("a");</span><br><br><span style="font-size: 14pt"> list.addeventlistener("touchstart",start);</span><br><span style="font-size: 14pt"> list.addeventlistener("touchmove",move);</span><br><span style="font-size: 14pt"> list.addeventlistener("touchend",end);</span><br><br><span style="font-size: 14pt"> list.innerhtml+=list.innerhtml;</span><br><span style="font-size: 14pt"> len=list.children.length;</span><br><span style="font-size: 14pt"> console.log(len);</span><br><span style="font-size: 14pt"> list.style.width=w*len+"px"; </span><br><br><span style="font-size: 14pt"> function start(ev){</span><br><span style="font-size: 14pt"> clearinterval(timer);</span><br><span style="font-size: 14pt"> var e=ev.changedtouches[0];</span><br><span style="font-size: 14pt"> disx=e.pagex;</span><br><span style="font-size: 14pt"> list.style.transition="none";</span><br><span style="font-size: 14pt"> var num=math.round(list.offsetleft/w);</span><br><span style="font-size: 14pt"> list.style.left=num*w+"px";</span><br><span style="font-size: 14pt"> if(num==0){</span><br><span style="font-size: 14pt"> num=a.length;</span><br><span style="font-size: 14pt"> list.style.left=-num*w+"px";</span><br><span style="font-size: 14pt"> }</span><br><span style="font-size: 14pt"> if(-num==len-1){</span><br><span style="font-size: 14pt"> num=a.length-1;</span><br><span style="font-size: 14pt"> list.style.left=-num*w+"px";</span><br><span style="font-size: 14pt"> }</span><br><span style="font-size: 14pt"> listl=this.offsetleft;</span><br><span style="font-size: 14pt"> }</span><br><span style="font-size: 14pt"> function move(ev){</span><br><span style="font-size: 14pt"> var e=ev.changedtouches[0];</span><br><span style="font-size: 14pt"> list.style.left=(e.pagex-disx)+listl+"px";</span><br><span style="font-size: 14pt"> }</span><br><span style="font-size: 14pt"> function end(){</span><br><span style="font-size: 14pt"> var num=math.round(list.offsetleft/w);</span><br><span style="font-size: 14pt"> console.log(num)</span><br><span style="font-size: 14pt"> list.style.transition="0.5s";</span><br><span style="font-size: 14pt"> list.style.left=num*w+"px"; </span><br><span style="font-size: 14pt"> a[n].classname="";</span><br><span style="font-size: 14pt"> a[(-num)%a.length].classname="active";</span><br><span style="font-size: 14pt"> n=(-num)%a.length;</span><br><span style="font-size: 14pt"> timer=setinterval(function(){</span><br><span style="font-size: 14pt"> inn();</span><br><span style="font-size: 14pt"> },1000)</span><br><span style="font-size: 14pt"> s=-num;</span><br><span style="font-size: 14pt"> }</span><br><br><span style="font-size: 14pt"> timer=setinterval(function(){</span><br><span style="font-size: 14pt"> inn();</span><br><span style="font-size: 14pt"> },1000)</span><br><br><span style="font-size: 14pt"> function inn(){</span><br><span style="font-size: 14pt"> s++;</span><br><span style="font-size: 14pt"> list.style.left=-s*w+"px";</span><br><span style="font-size: 14pt"> list.style.transition="0.5s";</span><br><span style="font-size: 14pt"> console.log(s);</span><br><span style="font-size: 14pt"> if(s>len-1){</span><br><span style="font-size: 14pt"> s=a.length-1;</span><br><span style="font-size: 14pt"> list.style.transition="none";</span><br><span style="font-size: 14pt"> list.style.left=-s*w+"px";</span><br><span style="font-size: 14pt"> console.log(list.style.left);</span><br><span style="font-size: 14pt"> settimeout(function(){ </span><br><span style="font-size: 14pt"> list.style.transition="0.5s";</span><br><span style="font-size: 14pt"> s++;</span><br><span style="font-size: 14pt"> list.style.left=-s*w+"px";</span><br><span style="font-size: 14pt"> a[n].classname="";</span><br><span style="font-size: 14pt"> a[s%a.length].classname="active";</span><br><span style="font-size: 14pt"> n=s%a.length;</span><br><span style="font-size: 14pt"> },30)</span><br><span style="font-size: 14pt"> }</span><br><span style="font-size: 14pt"> a[n].classname="";</span><br><span style="font-size: 14pt"> a[s%a.length].classname="active";</span><br><span style="font-size: 14pt"> n=s%a.length; </span><br><span style="font-size: 14pt"> }</span><br><span style="font-size: 14pt"> </script></span><br><span style="font-size: 14pt"></body></span><br><span style="font-size: 14pt"></html></span></p> </div> <div class="info-pre-next"> <p> 上一篇: <a href="/article/302138.html"> 序列化组建 </a> </p> <p> 下一篇: <a href="/article/302140.html"> c#在pictureBox控件上绘制多个矩形框及删除绘制的矩形框 </a> </p> </div> <div class="wz_tuijian"> <p> 推荐阅读 </p> <ul> <li> <a href="/article/2257668.html" target="_blank" title="Html5移动端获奖无缝滚动动画实现示例"> <h2> Html5移动端获奖无缝滚动动画实现示例 </h2> </a> </li> <li> <a href="/article/2208527.html" target="_blank" title="Html5移动端获奖无缝滚动动画实现示例"> <h2> Html5移动端获奖无缝滚动动画实现示例 </h2> </a> </li> <li> <a href="/article/2172198.html" target="_blank" title="基于zepto的插件之移动端无缝向上滚动并上下触摸滑动实例代码"> <h2> 基于zepto的插件之移动端无缝向上滚动并上下触摸滑动实例代码 </h2> </a> </li> <li> <a href="/article/1994408.html" target="_blank" title="vue移动端裁剪图片结合插件Cropper的使用实例代码"> <h2> vue移动端裁剪图片结合插件Cropper的使用实例代码 </h2> </a> </li> <li> <a href="/article/1989663.html" target="_blank" title="js 简易版滚动条实例(适用于移动端H5开发)"> <h2> js 简易版滚动条实例(适用于移动端H5开发) </h2> </a> </li> <li> <a href="/article/1916487.html" target="_blank" title="Vue.js 2.0 移动端拍照压缩图片预览及上传实例"> <h2> Vue.js 2.0 移动端拍照压缩图片预览及上传实例 </h2> </a> </li> <li> <a href="/article/1835658.html" target="_blank" title="利用Vue实现移动端图片轮播组件的方法实例"> <h2> 利用Vue实现移动端图片轮播组件的方法实例 </h2> </a> </li> <li> <a href="/article/1788370.html" target="_blank" title="js实现图片区域可点击大小随意改变(适用移动端)代码实例"> <h2> js实现图片区域可点击大小随意改变(适用移动端)代码实例 </h2> </a> </li> <li> <a href="/article/1773975.html" target="_blank" title="基于zepto的插件之移动端无缝向上滚动并上下触摸滑动实例代码"> <h2> 基于zepto的插件之移动端无缝向上滚动并上下触摸滑动实例代码 </h2> </a> </li> <li> <a href="/article/1658838.html" target="_blank" title="【常见】移动端实例——图片无缝滚动"> <h2> 【常见】移动端实例——图片无缝滚动 </h2> </a> </li> </ul> </div> </article> </div> </main> <footer><div class="box"><div class="ft_nav"><div class="ft_about"><p>关于网站</p><ul><li><a href="/sitemap.xml" target="_blank" title="网站地图">网站地图</a></li><li><a href="/list/2/" title="最新程序员文章站">最新程序员文章站</a></li></ul></div><div class="ft_contact"><ul><li>本站所有数据收集于网络如有侵犯到您的权益,请联系我们进行下架处理。</li><li class="email_show"></li></ul></div></div><div class="copyright"><div class="cr_left"><p> 备案号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20058927号</a></p><p>© Copyright © 2020-2022 www.superweb999.com 程序员文章站. </p></div></div></div></footer> </body> </html>