码迷,mamicode.com
首页 > 移动开发 > 详细

手机版 div拖动

时间:2016-12-03 07:51:47      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:type   mouse   oct   abs   ext   false   rip   手机   code   

<!doctype html>
<html> 
<head> 
<title></title> 
<script type="text/javascript"> 
var mouseX; 
var objX; 
var isDowm = false; //是否按下鼠标 
function mouseDown(obj, e) { 
obj.style.cursor = "move"; 

mouseX = e.clientX;
isDowm = true; 
} 
function mouseMove(e) { 
var div = document.getElementById("div1"); 
var x = e.clientX;
if (isDowm) { 
div.style.left = parseInt(objX) + parseInt(x) - parseInt(mouseX) + "px"; 
} 
} 
function mouseUp(e) { 
if (isDowm) { 
var x = e.clientX;
var div = document.getElementById("div1"); 
div.style.left = (parseInt(x) - parseInt(mouseX) + parseInt(objX)) + "px";
mouseX = x;
div1.style.cursor = "default";
isDowm = false; 
} 
} 
</script> 
</head> 
<body> 
<div id="div1" style="background-color: Green; border: 1px solid red; height: 300px; 
top: 100px; left: 100px; width: 300px; position: absolute;" onmousedown="mouseDown(this,event)" 
onmousemove="mouseMove(event)" onmouseup="mouseUp(event)"> 
</div> 
</body> 
</html>

 

手机版 div拖动

标签:type   mouse   oct   abs   ext   false   rip   手机   code   

原文地址:http://www.cnblogs.com/manyu/p/6127867.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!