zoukankan      html  css  js  c++  java
  • js 拖拽

    <title>无标题文档</title>
    <style>
    #div1{ width:200px; height:200px; position:absolute; background:red;}
    </style>
    </head>
    <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;
                    }
            }
            
        }
    </script>
    
    <body>
    <div id="div1"></div>
    </body>
    </html>
  • 相关阅读:
    一种想法
    识别link_text
    识别name
    识别id
    文件的读写
    条件和循环
    网站测试-功能测试小结
    拷贝
    #团队博客作业1-小组成员介绍
    软件测试基础-Homework1
  • 原文地址:https://www.cnblogs.com/zxl89/p/6412797.html
Copyright © 2011-2022 走看看