[JavaScript]可移动的DIV
1function divdrag(obj)
2{
3 var s = obj.style
4 var b = document.body
5 var x = event.clientX + b.scrollLeft - s.pixelLeft
6 var y = event.clientY + b.scrollTop - s.pixelTop
7 var m = function()
8 {
9 if (event.button == 1)
10 {
11 s.pixelLeft = event.clientX + b.scrollLeft - x
12 s.pixelTop = event.clientY + b.scrollTop - y
13 }
14 else document.detachEvent("onmousemove", m)
15 }
16 document.attachEvent("onmousemove", m)
17 event.cancelBubble = true
18}
2{
3 var s = obj.style
4 var b = document.body
5 var x = event.clientX + b.scrollLeft - s.pixelLeft
6 var y = event.clientY + b.scrollTop - s.pixelTop
7 var m = function()
8 {
9 if (event.button == 1)
10 {
11 s.pixelLeft = event.clientX + b.scrollLeft - x
12 s.pixelTop = event.clientY + b.scrollTop - y
13 }
14 else document.detachEvent("onmousemove", m)
15 }
16 document.attachEvent("onmousemove", m)
17 event.cancelBubble = true
18}