zoukankan      html  css  js  c++  java
  • 原生拖放代码

    这段js代码会让页面所有position:absolute;的元素可以拖动

    var chef = (function(){
            var drawDiv,ofstX,ofstY;
    
            function fun(event){
                var event = event || window.event;
                var target = event.target || event.srcElement;
                switch(event.type){
                    case "mousedown":
                                drawDiv = target;
                                ofstX = event.clientX-drawDiv.offsetLeft;
                                ofstY = event.clientY-drawDiv.offsetTop;
                        break;
                    case "mousemove":
                            if(drawDiv != null){
                                drawDiv.style.left = event.clientX - ofstX + "px";
                                drawDiv.style.top = event.clientY - ofstY + "px";
                            }
                        break;
                    case "mouseup":
                        drawDiv = null;
                        break;
    
                }
            };
    
            document.body.onmousedown = function(event){fun(event);};
            document.body.onmousemove = function(event){fun(event);};
            document.body.onmouseup   = function(event){fun(event);};
        })();
  • 相关阅读:
    BJDCTF-WP
    Python 每日一练(4)
    Python 每日一练(3)
    BUUCTF Crypto
    Python每日一练(1)
    Python 每日一练(2)
    oracle 组函数
    oracle 组函数
    oracle
    前端实战遇到问题
  • 原文地址:https://www.cnblogs.com/chefweb/p/6059450.html
Copyright © 2011-2022 走看看