zoukankan      html  css  js  c++  java
  • [转载]JS拖动技术 关于setCapture

    <script type="text/javascript">
    <!--
    window.onload=function(){
      objDiv = document.getElementByIdx('drag');
      drag(objDiv);
    };

    function drag(dv){
      dv.onmousedown=function(e){
          var d=document;
          e = e || window.event;
         
          var x= e.layerX || e.offsetX;
          var y= e.layerY || e.offsetY;
         
          //设置捕获范围
          if(dv.setCapture){
              dv.setCapture();
          }else if(window.captureEvents){
              window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
          }
         

          d.onmousemove=function(e){
               e= e || window.event;
               if(!e.pageX)e.pageX=e.clientX;
               if(!e.pageY)e.pageY=e.clientY;
               var tx=e.pageX-x;
               var ty=e.pageY-y;
              
               dv.style.left=tx;
               dv.style.top=ty;
          };

          d.onmouseup=function(){
               //取消捕获范围
               if(dv.releaseCapture){
                  dv.releaseCapture();
               }else if(window.captureEvents){
                  window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
               }
              
              //清除事件
              d.onmousemove=null;
              d.onmouseup=null;
          };
       };
    }
    //-->
    </script>

    --------
    <div id="drag" >drag me <div>

    --------------------------------------
    setCapture 的意思就是设置一个对象的方法被触发的范围,或者作用域。
    如果不设置,则div只在当前窗口内被触发。如果设置,则在整个浏览器范围内被触发,也就是可以拖到浏览器外面

  • 相关阅读:
    win7常用快捷键
    java中构造代码块、方法调用顺序问题
    eclipse项目改为maven项目导致svn无法比较历史数据的解决办法
    linux配置Anaconda python集成环境
    DataFrame对行列的基本操作实战
    驱动:电阻屏触摸芯片NS2009
    读书笔记:代码大全(第二版)
    资料:磁角度传感器芯片
    经验:FatFs文件系统实时写入
    笔记:CAN收发器-TJA1051T与TJA1051T/3调试总结
  • 原文地址:https://www.cnblogs.com/canphp/p/2165312.html
Copyright © 2011-2022 走看看