核心代码 :
<! DocType html> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8" /> <title> 鼠标拖动和拖拽的鼠标指针特效 </title> <style> #box {width: 100px; Höhe: 100px; Hintergrund:#966; Position: absolut; links: 100px; top: 100px; {width: math.max (document.documentElement.clientwidth, document.documentElement.scrollwidth), Höhe: math.max (document.documentElement.clientHeight, document.documentElement.scrollHeight)}; Fall X> maxnum: x = maxnum; brechen; Standard: x; } return x; } box.style.left = '100px'box.style.top =' 100px'box.onmouseDown = Funktion (e) {var e = e || window.event; var maxl = getViewport (). width-100, maxt = getViewPort (). Höhe-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+':'+max+':'+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 = Compunenum (x, minl, maxl)+'px' box.style.top = vergleicheum (y, mint, max)+'px'} </script> </body> </html>[Strg+a 全选 注: 如需引入外部 js 需刷新才能执行]