如下所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <title>Document</title> </head> <style> html{height:100%;} body{width: 100%;height:100%;margin:0;overflow: hidden;} .wrap{position: relative;overflow: hidden;} .box{position: absolute;list-style: none;left:0;top:0;padding:0;margin:0;} .box li{float:left;} .box{ position: relative; height: 2000px; width: 100%; top: 0; bottom: 0; left: 0; right: 0; background: red; } .box1{ height: 2000px; } .box2{ background: yellow; } .box3{ background: yellowgreen; } .box4{ background: orange; } .box5{ background: cyan; } </style> <body> <div class="wrap"> <ul class="box"> <li><div class="box1 box2">11111</div></li> <li><div class="box1 box3">2222</div></li> <li><div class="box1 box4">3333</div></li> <li><div class="box1 box5">4444</div></li> </ul> </div> <script> var aLi = document.querySelectorAll(".box li"); var box = document.querySelector('.box'); var wrap = document.querySelector('.wrap'); var aLiWidth = box.offsetWidth; console.log('aLiWidth: ' + aLiWidth) wrap.style.height = aLi[0].offsetHeight + 'px'; // 设置盒子的宽度 box.style.width = aLi.length*100 + '%'; for(var i=0;i<aLi.length;i++){ aLi[i].style.width = 1/aLi.length * 100 + '%'; }; // 初始化手指坐标点 var startPoint = 0; var startEle = 0; //手指按下 wrap.addEventListener("touchstart",function(e){ startPoint = e.changedTouches[0].pageX; startEle = box.offsetLeft; }); //手指滑动 wrap.addEventListener("touchmove",function(e){ var currPoint = e.changedTouches[0].pageX; var disX = currPoint - startPoint; var left = startEle + disX; box.style.left = left + 'px'; }); //当手指抬起的时候,判断图片滚动离左右的距离,当 wrap.addEventListener("touchend",function(e){ var left = box.offsetLeft; // 判断正在滚动的图片距离左右图片的远近,以及是否为最后一张或者第一张 var currNum = Math.round(-left/aLiWidth); currNum = currNum>=(aLi.length-1) ? aLi.length-1 : currNum; currNum = currNum<=0 ? 0 : currNum; box.style.left = -currNum*wrap.offsetWidth + 'px'; }) </script> </body> </html>
以上这篇js原生实现移动端手指滑动轮播图效果的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“js原生实现移动端手指滑动轮播图效果的示例”评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新动态
2024年05月09日
2024年05月09日
- 群星《越洋电话, Vol. 1》[FLAC/分轨][114.98MB]
- 林志颖.1992-为什么受伤的总是我【飞碟】【WAV+CUE】
- 羽泉.2005-三十【华谊兄弟】【WAV+CUE】
- 白嘉莉.2021-精选集【海山】【WAV+CUE】
- 欢乐钓鱼大师玛瑙金鳞怎么钓 欢乐钓鱼大师玛瑙金鳞钓鱼攻略
- 欢乐钓鱼大师樱飘雪怎么钓 欢乐钓鱼大师樱飘雪钓鱼攻略
- 欢乐钓鱼大师银翼的奇术师怎么钓 欢乐钓鱼大师银翼的奇术师钓鱼攻略
- 陈琳.1994-你的柔情我永远不懂[WAV]
- 邓瑞霞2006-广东风云2IN1[南方]2CD[WAV+CUE]
- 黄征-爱情诺曼底-2003-APE整轨
- 妥协只是暂时的!《对马岛之魂》PC版的多人模式仍需绑定PSN
- 开启抢先体验后 《盗贼之海》成PS美国第二畅销游戏
- 《恶意不息》老板再用中文询问中国玩家:对汉化是否满意
- 2个女生.2000-坚固友情精选辑【EMI百代】【WAV+CUE】
- 潘越云李丽芬吴楚楚.1981-三人展(滚石民歌巨星系列)【滚石】【WAV+CUE】.