首頁 >web前端 >js教程 >可以滑鼠拖曳的DIV實現思路及程式碼_javascript技巧

可以滑鼠拖曳的DIV實現思路及程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:19:28882瀏覽
閱讀頁閱讀:


div div div <br> <br>var offset_x; <br>var offset_y; <br>function Milan_StartMove(oEvent) <br>{ <br>var whichButton; <br>if(document.all&oEvent.button==1)whichButton=true; <br>else { if(oEvent.button==0)whichButton=true;} <br>if(whichButton) <br>{ <br>var oDiv=document.getElementById("oDiv"); <br>offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft); <br>offset_y=parseInt(oEvent.clientY-oDiv.offsetTop); <br>document.documentElement.onmousemove=function(mEvent) <br>{ <br>var eEvent; <br>if(document.all) eEvent=事件 <br>else{eEvent=mEvent;} <br>var oDiv=document.getElementById("oDiv"); <br>var x=eEvent.clientX-offset_x; <br>var y=eEvent.clientY-offset_y; <br>oDiv.style.left=(x) "px"; <br>oDiv.style.top=(y) "px"; <br>} <br>} <br>} <br>function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; } <br>腳本>; <br>頭> <br> <br><div id="oDiv" onmousedown="Milan_StartMove(event)" onmouseup="Milan_StopMove(event)"> <br>style="cursor:移動;位置:絕對;寬度:100px;高度:60px;尺寸:<br><br><br><br>銀色;左:100px; /body> </div> <br> <br> document.all[] Document.all[] Document.素;<br>event.button的值:0沒第1, 2, 3, 3, 4, 5, 5, 6, 6, 7 吋的正方形🎜 >我想知道,我想知道,我想,我想<br><br><div class="codetitle"><span><a style="CURSOR: pointer" data="19869" class="copybut" id="copybut19869" onclick="doCopy('code19869')"><u></u></a></span></div>:<div class="codebody" id="code19869"> <br> <br> <br> <br><title>測試可動div

var offset_x;
var offset_y;
function Milan_StartMove(oEvent,div_id)
{
var whichButton;
if(document.all&oEvent.button==1)whichButton=true;
else { if(oEvent.button==0)whichButton=true;}
if(whichButton)
{
var oDiv=div_id;
offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft);
offset_y=parseInt(oEvent.clientY-oDiv.offsetTop);
document.documentElement.onmousemove=function(mEvent)
{
var eEvent;
if(document.all) eEvent=事件
else{eEvent=mEvent;}
var oDiv=div_id;
var x=eEvent.clientX-offset_x;
var y=eEvent.clientY-offset_y;
oDiv.style.left=(x) "px";
oDiv.style.top=(y) "px";
var d_oDiv=document.getElementById("disable_" oDiv.id);
d_oDiv.style.left=(x) "px";
d_oDiv.style.top=(y) "px";
}
}
}
function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; }
函數 div_Close(o)
{var oDiv=o; oDiv.style.display="none";var d_oDiv=document.getElementById("disable_" o.id);d_oDiv.style.display="none";}
;
頭>


style="cursor:move; width:100%;height:15px; 字體大小:10px;">
分區>


3331111選項>
222選項>
選擇>
>
> 🎜 >

用select div建立一個div 如果你想建立一個IE,你想建立一個parentElement 如果你想建立一個parentNode,建立一個CSS,建立一個FF帳戶,建立父節點。
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:用Js實現的動態增加表格範例自己寫的_javascript技巧下一篇:用Js實現的動態增加表格範例自己寫的_javascript技巧

相關文章

看更多