论坛首页 Web前端技术论坛

偶写的dragdrop方法,可以很方便的实现拖拽操作

浏览 2714 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-11-02  

用到了jquery,函数原型如下:

js 代码
  1. /*  
  2.  * @src handle element  
  3.  * @on_mousedown  function(handlingElement,x,y)  
  4.  * @on_mousemove  function(handlingElement,dx,dy,ddx,ddy,x,y);  
  5.  * x,y current x,y  
  6.  * dx,dy  delta x,y from mousedown  
  7.  * ddx,ddy delta x,y from last move  
  8.  */  
  9. function handleDrag(src,on_mousedown,on_mousemove){   
  10. ...   
  11. }  

 

例子:

js 代码
  1. $("td").each(function(){   
  2.     var ow,oh;//记录第一次的宽度和高度   
  3.     handleDrag(this,   
  4.         function(src,x,y){   
  5.             ow=$(src).width();   
  6.             oh=$(src).height();   
  7.         },   
  8.         function(src,x,y,dx,dy,ddx,ddy){   
  9.             p=$(src);   
  10.             p.width(ow+dx);   
  11.             p.height(oh+dy);   
  12.     });   
  13. });  
   发表时间:2007-11-09  
多次拖拽,发现越来越慢,不知何故
0 请登录后投票
   发表时间:2007-11-13  
jquery有拖动到插件吧,没有必要自己再写吧
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics