當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
弹出对话框拖拽JavaScript实现
生活随笔
收集整理的這篇文章主要介紹了
弹出对话框拖拽JavaScript实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
html代碼
<div id="box"></div>css代碼
* {margin: 0;padding: 0;}#box {width: 100px;height: 100px;background: red;position: absolute;}JS代碼
var Box = document.getElementById("box");var iw = document.documentElement.clientWidth - Box.offsetWidth;Box.onmousedown = function (e) {var e = e || event;var disX = e.offsetX;var disY = e.offsetY;document.onmousemove = function (e) {var e = e || event;var l = e.clientX - disX;var t = e.clientY - disY;l = l >= iw ? l = iw : (l <= 0 ? l = 0 : l = l);t = t >= e.clientY ? t = e.clientY : (t <= 0 ? t = 0 : t = t);Box.style.left = l + "px";Box.style.top = t + "px";};document.onmouseup = function () {document.onmousemove = null;document.onmouseup = null;}}總結
以上是生活随笔為你收集整理的弹出对话框拖拽JavaScript实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 贪吃的小猫教案一等奖
- 下一篇: gradle idea java ssm