手机版 div拖动

Posted 涵枫筱怡

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手机版 div拖动相关的知识,希望对你有一定的参考价值。

<!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拖动的主要内容,如果未能解决你的问题,请参考以下文章

hmtl 手机上 div元素 拖动

jquery ui可拖动手机版

贡献一下多年珍藏的特效例子

如何实现拖动修改网页中div模块大小

安卓游戏模拟器电脑版怎么设置按键

JavaFX窗口拖动