當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

如何控制對象拖動

如何控制對象拖動

更新時間:2020-11-25 文章作者:未知 信息來源:網絡 閱讀次數:


<SCRIPT LANGUAGE="JavaScript">
<!--
var currentMoveObj = null;        //當前拖動對象
var relLeft;        //鼠標按下位置相對對象位置
var relTop;
var zindex=-1;//控制被拖動對象的z-index值
function f_mdown(obj)
{
        currentMoveObj = obj;                //當對象被按下時,記錄該對象
        currentMoveObj.style.position = "absolute";
        relLeft = event.x - currentMoveObj.style.pixelLeft;
        relTop = event.y - currentMoveObj.style.pixelTop;
        zindex=currentMoveObj.style.zIndex;//記錄原z-index值
        currentMoveObj.style.zIndex=10000;
}
window.document.onmouseup = function()
{      currentMoveObj.style.zIndex=zindex;//恢復
        zindex=-1;        currentMoveObj = null;        //當鼠標釋放時同時釋放拖動對象
       }
function f_move(obj)
{
        if(currentMoveObj != null)
        {
                currentMoveObj.style.pixelLeft=event.x-relLeft;
                currentMoveObj.style.pixelTop=event.y-relTop;
        }
}//-->
</SCRIPT>
<BODY>
<TABLE width="100" border=1 onselectstart="return false" style="position:absolute;left:50;top:50" onmousedown="f_mdown(this)" onmousemove="f_move(this)">
<TR>
        <TD bgcolor="#CCCCCC" align="center" style="cursor:move">title1</TD>
</TR>
<TR>
        <TD align="center" height="60">content</TD>
</TR>
</TABLE>
<TABLE width="100" border=1 onselectstart="return false" style="position:absolute;left:350;top:250" onmousedown="f_mdown(this)" onmousemove="f_move(this)">
<TR>
        <TD bgcolor="#CCCCCC" align="center" style="cursor:move">title2</TD>
</TR>
<TR>
        <TD align="center" height="60">content</TD>
</TR>
</TABLE>
</BODY>

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
亚洲嫩草影院久久精品