js实现简单鼠标拖拽,文件拖入文件夹效果
2014-05-06 20:25
831 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>简单鼠标拖拽</title> <style type="text/css"> #dray { position: absolute; left: 0; top: 0; width: 300px; height: 300px; background-color: red; -moz-user-select: none; } #box { width: 400px; height: 400px; margin-left: 500px; margin-top: 200px; background-color: green; } </style> </head> <body onload="dvDray()"> <div id="dray">拖我</div> <div id="box">拖到我这里来</div> <script type="text/javascript"> function dvDray() { var dv = document.getElementById("dray"); var d = document, x, y; dv.onselectstart = function () { return false; }; dv.onmousedown = function (e) { e = e || window.event; x = e.clientX - dv.offsetLeft; y = e.clientY - dv.offsetTop; d.onmousemove = function (e) { e = e || window.event; var el = e.clientX - x; var et = e.clientY - y; dv.style.left = el + "px"; dv.style.top = et + "px"; checkDvPosition(el, et); }; d.onmouseup = function () { d.onmousemove = null; }; }; } function checkDvPosition(ol, ot) { var b = document.getElementById("box"); var l = b.offsetLeft; var t = b.offsetTop; if (ol > l && ot > t && ol < l + 100 && ot < t + 100) { b.style.backgroundColor = "blue"; } else { b.style.backgroundColor = "green"; } } </script> </body> </html>
相关文章推荐
- 简单实现js鼠标跟随效果
- js最简单的拖拽效果实现代码
- js 实现无干扰阴影效果 简单好用(附文件下载)
- 简单实现js拖拽效果
- js实现百度登录框鼠标拖拽效果
- JS实现的简单鼠标跟随DiV层效果完整实例
- Java实现拖拽文件上传dropzone.js的简单使用示例代码
- js实现简单鼠标跟随效果的方法
- js实现登录框鼠标拖拽效果
- js实现本地图片文件拖拽效果
- 用js实现简单的鼠标跟随效果
- js最简单的拖拽效果实现代码
- js 实现无干扰阴影效果 简单好用(附文件下载)
- 使用js实现的简单拖拽效果
- JS实现超简单的鼠标拖动效果
- JS实现简单拖拽效果
- JS实现的简单鼠标跟随DiV层效果完整实例
- JS实现超简单的鼠标拖动效果
- js实现鼠标拖拽效果
- js实现一个简单的数字时钟效果