zoukankan      html  css  js  c++  java
  • 可拖动的div

    ##

    <!DOCTYPE html>  
    <html>    
    <head runat="server">    
        <title></title>    
        <style>  
            #mov{  
                background-color: #00DDCC;  
                width: 200px;  
                height: 200px;    
                top: 100px;  
                left: 100px;    
                position: absolute;  
            }  
        </style>  
        <script>
            var mouseX, mouseY;
            var objX, objY;
            var isDowm = false;
            function mouseDown(obj, e) {
                var div = document.getElementById("mov");
                obj.style.cursor = "move";
                objX = div.offsetLeft;
                objY = div.offsetTop;
                mouseX = e.clientX;
                mouseY = e.clientY;
                isDowm = true;
            }
            function mouseMove(e) {
                var div = document.getElementById("mov");
                var x = e.clientX;
                var y = e.clientY;
                if (isDowm) {
                    div.style.left = parseInt(objX) + parseInt(x) - parseInt(mouseX) + "px";
                    div.style.top = parseInt(objY) + parseInt(y) - parseInt(mouseY) + "px";
                }
            }
            function mouseUp(e) {
                if (isDowm) {
                    var x = e.clientX;
                    var y = e.clientY;
                    var div = document.getElementById("mov");
                    div.style.left = parseInt(objX) + parseInt(x) - parseInt(mouseX) + "px";
                    div.style.top = parseInt(objY) + parseInt(y) - parseInt(mouseY) + "px";
                    div.style.cursor = "default";
                    isDowm = false;
                }
            }
        </script>  
    </head>    
    <body>    
        <div id="mov" onmousedown="mouseDown(this,event)" onmousemove="mouseMove(event)" onmouseup="mouseUp(event)"></div>   
    </body>    
    </html>  
  • 相关阅读:
    angularjs 判断是否包含 permIDs|filter:'10'
    js日期格式化
    JSON格式检验
    CodeSmith Generator 6.5
    Hosts文件说明
    正则表达式匹配换行实例代码
    Codeforces 311E Biologist
    URAL 1349 Farm
    [SDOI2015] 序列统计
    洛谷 P3803 多项式乘法
  • 原文地址:https://www.cnblogs.com/tinaluo/p/9034878.html
Copyright © 2011-2022 走看看