首页 > 代码库 > 手机版 div拖动
手机版 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;" onm ousedown="mouseDown(this,event)" onmousemove="mouseMove(event)" onm ouseup="mouseUp(event)"> </div> </body> </html>
手机版 div拖动
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。