zoukankan      html  css  js  c++  java
  • 精简版拖动

    /* 鼠标拖动 */
    var oDrag = "";
    var ox,oy,nx,ny,dy,dx;
    function drag(e,o){
     var e = e ? e : event;
     var m = document.all ? 1 : 0;
     if(e.button == m)
     {
      if (o.parentNode)
      {
       oDrag = o.parentNode;
      }
      else{oDrag = o;}
      ox = e.clientX;
      oy = e.clientY;  
     }
    }
    function dragPro(e){
     if(oDrag != "")
     { 
      //var obj=document.getElementById("msg");//拖动的id
      var obj=oDrag;//拖动的id
      var e = e ? e : event;
      obj.style.position = 'absolute';
      dx = parseInt(obj.style.left);
      dy = parseInt(obj.style.top);
      if(isNaN(dx)){dx=0;}
      if(isNaN(dy)){dy=0;}
      nx = e.clientX;
      ny = e.clientY;
      obj.style.left = (dx + ( nx - ox )) + "px";
      obj.style.top = (dy + ( ny - oy )) + "px";
      ox = nx;
      oy = ny;
     }
    }
    document.onmouseup = function(){oDrag = "";}
    document.onmousemove = function(event){dragPro(event);}


    调用的时候onmousedown='drag(event,this)'

    不会用博客园的贴效果……演示无法提供……
  • 相关阅读:
    【转】java线程池ThreadPoolExecutor使用介绍
    java的类加载机制
    java面试问题分类
    ConcurrentHashMap总结
    ffmpeg对视频封装和分离
    SSM的整合
    单例模式的七种写法
    SecureCRT的快捷键
    linux下mysql常用命令
    maven操作
  • 原文地址:https://www.cnblogs.com/rayking/p/1216396.html
Copyright © 2011-2022 走看看