首页 > 移动平台 > 详细

手机版 div拖动

时间:2016-12-03 07:51:42      阅读:198      评论:0      收藏:0      [点我收藏+]
<!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拖动

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!