Javascriptを使用してdivレイヤを移動-javascriptドラッグレイヤ

5285 ワード

Javascriptを使用してdivレイヤを移動-javascriptドラッグレイヤ:
プログラム機能:javascriptを利用してインタフェース上で以下のhtml code中のdiv層を随意にドラッグする.
JAvascript移動divレイヤ-javascriptドラッグレイヤコード-
html code:
 
  



JAvascript移動divレイヤ-javascriptドラッグレイヤコード-javascript code:
 
  
<br>// javascript <br>/* <br>//onmousedown="movetianyamessage(div_Info, event)" onmousemove="movetianyamessageend(event);" <br>//onmouseup="movetianyamessageend(event)" onmouseout="movetianyamessageend(event)" <br>//onmousedown= onmousemove= onmouseup= onmouseout= <br>*/ <br>var tianyamessage = '' <br>var iLayerMaxNum = 999; <br>document.onmouseup = movetianyamessageend; <br>document.onmousemove = movetianyamessagestart; <br>var tianyamessagepixefX; <br>var tianyamessagepixefY; <br>function movetianyamessage(Object, event) <br>{ <br>tianyamessage = Object.id; <br>if(document.all) <br>{ <br>document.getElementById(tianyamessage).setCapture(); <br>tianyamessagepixefX = event.x - document.getElementById(tianyamessage).style.pixelLeft; <br>tianyamessagepixefY = event.y - document.getElementById(tianyamessage).style.pixelTop; <br>} <br>else if(window.captureEvents) <br>{ <br>window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); <br>tianyamessagepixefX = event.layerX; <br>tianyamessagepixefY = event.layerY; <br>} <br>document.getElementById(tianyamessage).style.zIndex = iLayerMaxNum; <br>iLayerMaxNum = iLayerMaxNum + 1; <br>} <br>function movetianyamessagestart(evt) <br>{ <br>if(tianyamessage!=''){ <br>if(document.all) <br>{ <br>document.getElementById(tianyamessage).style.left = event.x - tianyamessagepixefX; <br>document.getElementById(tianyamessage).style.top = event.y - tianyamessagepixefY; <br>} <br>else if(window.captureEvents) <br>{ <br>document.getElementById(tianyamessage).style.left = (evt.clientX - tianyamessagepixefX) + "px"; <br>document.getElementById(tianyamessage).style.top = (evt.clientY - tianyamessagepixefY) + "px"; <br>} <br>} <br>} <br>function movetianyamessageend(evt) <br>{ <br>if(tianyamessage!='') <br>{ <br>if(document.all) <br>{ <br>document.getElementById(tianyamessage).releaseCapture(); <br>tianyamessage=''; <br>} <br>else if(window.captureEvents){ <br>window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); <br>tianyamessage=''; <br>} <br>} <br>} <br>function disponse_div(obj) <br>{ <br>if(obj.style.display=="block") <br>{ <br>obj.style.display="none"; <br>} <br>else <br>{ <br>obj.style.display="block"; <br>} <br>} <br>