• 可以随鼠标拖拽的div


    可以拖拽的div

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <style>
    #div1 {100px; height:100px; background:red; position:absolute;}
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>可以拖拽的div</title>
    <script>
    window.onload=function ()
    {
        var oDiv=document.getElementById('div1');
        
        var disX=0;
        var disY=0;
        
        oDiv.onmousedown=function (ev)
        {
            var oEvent=ev||event;
            
            disX=oEvent.clientX-oDiv.offsetLeft;
            disY=oEvent.clientY-oDiv.offsetTop;
            
            document.onmousemove=function (ev)
            {
                var oEvent=ev||event;
                var l=oEvent.clientX-disX;
                var t=oEvent.clientY-disY;
                
                if(l<0)
                {
                    l=0;
                }
                else if(l>document.documentElement.clientWidth-oDiv.offsetWidth)
                {
                    l=document.documentElement.clientWidth-oDiv.offsetWidth;
                }
                
                if(t<0)
                {
                    t=0;
                }
                else if(t>document.documentElement.clientHeight-oDiv.offsetHeight)
                {
                    t=document.documentElement.clientHeight-oDiv.offsetHeight;
                }
                
                oDiv.style.left=l+'px';
                oDiv.style.top=t+'px';
            };
            
            document.onmouseup=function ()
            {
                document.onmousemove=null;
                document.onmouseup=null;
            };
            
            return false;
        };
    };
    </script>
    </head>
    
    <body>
    <div id="div1"></div>
    </body>
    </html>
    ..
  • 相关阅读:
    会议10
    会议09
    回忆8
    会议07
    团队报告三
    深圳展会问题关注
    移动电源频率设置
    安卓java设置字体颜色
    安卓取消默认的标题栏方法
    安卓,按钮清晰的事件注册写法
  • 原文地址:https://www.cnblogs.com/shoolnight/p/6410542.html
Copyright © 2020-2023  润新知