您的位置:首页 > 移动开发

关于zepto.js的移动端拖拽写法

2016-07-21 16:56 405 查看
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="和派孔明" />
<meta name="copyright" content="和派孔明" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
<title>关于zepto.js的移动端拖拽写法</title>
<style>
#div1{ position:absolute;left:0;top:0;width:200px; height:200px; background:#ccc;}
</style>
<script src="zepto.min.js"></script>

<script>
$(function(){

var disX = ev.targetTouches[0].pageX - $(this).position().left;
var disY = ev.targetTouches[0].pageY - $(this).position().top;

$(this).on("touchmove",function(ev){
$(this).css({
left:ev.targetTouches[0].pageX - disX + "px",
top:ev.targetTouches[0].pageY - disY + "px"
});
});

$(this).on("touchend",function(){
$(this).off('touchstart','touchmove');
});
});
});
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: