核心代码:
<! doctype html> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" เนื้อหา = "html; charset = utf-8" /> <title> 鼠标拖动和拖拽的鼠标指针特效 </title> <style> #Box {WIDTH: 100PX; ความสูง: 100PX; พื้นหลัง:#966; ตำแหน่ง: Absolute; ซ้าย: 100PX; TOP: 100PX; Cursor: Pointer;} </style> </head> <body> <body> {width: math.max (document.documentelement.clientWidth, documentEnumentElement.scrollwidth), ความสูง: Math.max (Document.documentElement.clientheight, DocumentEnumentElement.Scrollheight)};} การเปรียบเทียบฟังก์ชั่น x <minnum: x = minnum; break; กรณี x> maxnum: x = maxnum; break; ค่าเริ่มต้น: x; } return x; } box.style.left = '100px'box.style.top =' 100px'box.onmousedown = ฟังก์ชั่น (e) {var e = e || window.event; var maxl = getViewport (). width-100, maxt = getViewport (). ความสูง -100; this.startl = parseint (this.style.left); this.startt = parseint (this.style.top); //alert(e.clientx) this.startx = e.clientx; this.starty = e.clienty; // Alert (maxl+':'+maxt+':'+l+':'+t) doc.onmousemove = function (e) {posxy (e, 0,0, maxl, maxt); - doc.onmouseup = function () {doc.onmousemove = null; doc.onmouseup = null; - return false;} function posxy (e, minl, mint, maxl, maxt) {var e = e || window.event; var x = box.startl- (box.startx-e.clientx); var y = box.startt- (box.starty-e.clienty); box.style.left = เปรียบเทียบ (x, minl, maxl)+'px' box.style.top = เปรียบเทียบ (y, mint, maxt)+'px'} </script> </body> </html>[ctrl+a 全选注: 如需引入外部 js 需刷新才能执行]