移动开发,touchstart轮播图,移动端拖拽应用
2016-06-20 21:17
309 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> <title>和派孔明</title> <style> *{margin:0;padding:0;list-style:none;} #div1{position:relative;width:320px;height:150px; background:#ccc;margin:0 auto;overflow:hidden;} #div1 ul{position:absolute;left:0;top:0;width:3200px; height:150px;} #div1 ul li{float:left;width:320px;height:100%;line-height:150px;text-align:center;font-size:20px;} </style> <script> window.onload = function(){ var oDiv = document.getElementById("div1"); var oUl = oDiv.children[0]; var aLi = oUl.children; var len = aLi.length; oUl.addEventListener("touchstart",function(ev){ //取消运动 oUl.style.transition = "none"; var disX = ev.targetTouches[0].pageX - oUl.offsetLeft; function fnMove(ev){ oUl.style.left = ev.targetTouches[0].pageX - disX + "px"; } function fnEnd(){ oUl.removeEventListener("touchmove",fnMove,false); oUl.removeEventListener("touchend",fnEnd,false); //确定显示第几个 var n = Math.round(-oUl.offsetLeft/aLi[0].offsetWidth); if(n < 0){ n = 0; } else if(n >= len){ n = len - 1; } console.log(n); //添加运动 transition:0.7s all ease; oUl.style.transition = "0.7s all ease"; oUl.style.left = -n*aLi[0].offsetWidth + "px"; } oUl.addEventListener("touchmove",fnMove,false); oUl.addEventListener("touchend",fnEnd,false); ev.preventDefault(); },false); }; </script> </head> <body> <div id="div1"> <ul> <li style="background:#F3dab9;">0</li> <li style="background:#Fdfab9;">1</li> <li style="background:#F3ABF9;">2</li> <li style="background:#3AFBF9;">3</li> </ul> </div> </body> </html>
相关文章推荐
- git的创建新项目的使用
- Android-Android studio 出现 Error: NDK integration is deprecated in the current plugin. 问题解决
- 常用iOS的第三方框架
- iOS 判断字符串中含有某个字符串
- Ojective-C入门请读
- iOS_逆向_使用class dump导出头文件
- android 连接 wcf rest注意点
- iOS_逆向_使用dumpdecrypted砸壳
- App 版本信息等
- iOS webView加载网页失败,浏览器成功的原因,以及读取cookie
- 不同厂家的电脑进入bios的快捷键整理汇总
- Android(Java)之多线程结果返回——Future 、FutureTask、Callable、Runnable
- LruCache详解之 Android 内存优化
- "xxx" is not translated in "en" (English)
- android中自定义dialog的使用方法简介
- Unity3D如何构造小地图
- android 开发Handler源码剖析
- android 开发Handler源码剖析
- android 开发Handler源码剖析
- OC基础:协议Protocol