• 高级拖拽库


    此库的重点

    1.完成拖拽的基本操作

    2.清除浏览器拖拽的影响

    3.限制范围

    (function(w){
        w.$={};
        w.$.drag=function(testNode,callBack){
            //抽象元素一开始的位置
            var startPoint={x:0,y:0};
            //抽象鼠标一开始的位置
            var elementPoint={x:0,y:0};
            
            testNode.onmousedown=function(ev){
                ev = ev||event;
                // debugger
                //设置事件捕获
                if(testNode.setCapture){
                    testNode.setCapture();
                }
                // 初始状态是0,0
                startPoint.x = testNode.offsetLeft;
                startPoint.y = testNode.offsetTop;
                
                
                elementPoint.x = ev.clientX;
                elementPoint.y = ev.clientY;
                
                document.onmousemove=function(ev){
                    ev = ev||event;
                    var nowPoint={x:0,y:0};
                    nowPoint.x = ev.clientX;
                    nowPoint.y = ev.clientY;
                    
                    var L = startPoint.x + (nowPoint.x - elementPoint.x );
                    // 限制范围
                    if(L<0){ 
                        L=0;    
                    }else if(L>( testNode.parentNode.clientWidth -testNode.offsetWidth )){
                        L = testNode.parentNode.clientWidth - testNode.offsetWidth;
                    }
                    
                    testNode.style.left=L+"px";
                    
                    
                    if(callBack&&callBack["move"]&& typeof callBack["move"] === "function"){
                        callBack["move"].call(testNode);
                    }
                }
                
                document.onmouseup=function(){
                    document.onmousemove = document.onmouseup =null;//取消这两个事件
                    // 取消事件捕获
                    if(document.releaseCapture){
                        document.releaseCapture();
                    }
                }
                
                return false;
            }
        }
    })(window)
  • 相关阅读:
    右值全部内容
    右值和forward
    alg data以这本
    代码学习only3
    cpp未结
    接下来要处理
    两个进程通过共享内存同步,控制播放器关闭
    接下来
    选择修改还是扩展?
    loadrunner 无法保存许可信息
  • 原文地址:https://www.cnblogs.com/lufei910/p/12209629.html
Copyright © 2020-2023  润新知