js解决movebox移动问题
网络编程 2021-07-04 21:04www.168986.cn编程入门
这篇文章主要为大家详细介绍了js解决movebox移动问题,取消图片默认拖动事件,感兴趣的小伙伴们可以参考一下
本文为大家分享了js解决movebox移动问题,并且取消图片默认拖动事件的相关操作,供大家参考,具体内容如下
html:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link href="../Content/StyleSheet5.css" rel="stylesheet" /> <script src="../Scripts/JavaScript5.js"></script> <title></title> <meta charset="utf-8" /> </head> <body> <div id="center"> <div id="black"></div> <div id="movebox"> <img id="moveimg" src="../Images/b.jpg"/> </div> <img id="bigimg" src="../Images/b.jpg" /> </div> </body> </html>
js:
var movebox; window.onload = function () { movebox = document.getElementById("movebox"); movebox.addEventListener("mousedown", function (e) { if (e.button > 0) { fun2(); return false; } e.preventDefault && e.preventDefault(); //明哥:去掉图片拖动响应 狠重要 gen.x = e.clientX; gen.y = e.clientY; gen._x = movebox.offsetLeft; gen._y = movebox.offsetTop; gen.dx = gen.x - gen._x; gen.dy = gen.y - gen._y; document.addEventListener("mousemove",fun1,false); document.addEventListener("mouseup", fun2, false); }, false); }; var fun1 = function (e) { gen.L = e.clientX - gen.dx; gen.T = e.clientY - gen.dy; var timefun = function () { window.getSelection().removeAllRanges(); if (gen.L < 100) gen.L = 100; else if (gen.L > 200) gen.L = 200; if (gen.T < 125) gen.T = 125; else if (gen.T > 175) gen.T = 175; setLT(movebox, gen.L, gen.T); }; setTimeout(timefun, 2); }; var fun2 = function () { document.removeEventListener("mousemove", fun1, false); document.removeEventListener("mouseuo", fun2, false); }; var gen = { x: null, y: null, _x: null, _y: null, dx: null, dy: null, L: null, T:null, }; var setLT = function (dom, L, T) { dom.style.left = L + "px"; dom.style. = T + "px"; };
css:
body { position:absolute; margin:0; padding:0; } #center{ position:absolute; :200px; left:300px; width:400px; height:400px; background-color:#808080; } #black{ position:absolute; width:400px; height:400px; z-index:80; background-color:#000; opacity:0.6; } #bigimg{ z-index:50; position:absolute; left:100px; :125px; } #movebox{ z-index:100; position:absolute; width:100px; height:100px; left:150px; :150px; overflow:hidden; cursor:move; background-color:#ff6a00; } #moveimg{ position:absolute; left:-50px; :-25px; }
以上就是本文的全部内容,希望对大家的学习有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程