javascirpt div 移動應用

kevin_god發表於2009-02-25
可以用滑鼠拖動的DIV
2009-02-05 18:07
可以用滑鼠拖動的DIV


測試可動div

var offset_x;
        var offset_y;
        function Milan_StartMove(oEvent)
        {
            var whichButton;
            if(document.all&&oEvent.button==1) whichButton=true;
            else { if(oEvent.button==0)whichButton=true;}
            if(whichButton)
            {
                var Div=document.getElementById("oDiv");
                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=event;
                    else{eEvent=mEvent;}
                    var Div=document.getElementById("oDiv");
                    var x=eEvent.clientX-offset_x;
                    var y=eEvent.clientY-offset_y;
                    oDiv.style.left=(x)+"px";
                    oDiv.style.top=(y)+"px";
                }
            }
        }
function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; }



style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid

silver;left:100px;top:100px;z-index:9999;">


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17140602/viewspace-557851/,如需轉載,請註明出處,否則將追究法律責任。

相關文章