用到了jquery,函数原型如下:
js 代码
- /*
- * @src handle element
- * @on_mousedown function(handlingElement,x,y)
- * @on_mousemove function(handlingElement,dx,dy,ddx,ddy,x,y);
- * x,y current x,y
- * dx,dy delta x,y from mousedown
- * ddx,ddy delta x,y from last move
- */
- function handleDrag(src,on_mousedown,on_mousemove){
- ...
- }
例子:
js 代码
- $("td").each(function(){
- var ow,oh;//记录第一次的宽度和高度
- handleDrag(this,
- function(src,x,y){
- ow=$(src).width();
- oh=$(src).height();
- },
- function(src,x,y,dx,dy,ddx,ddy){
- p=$(src);
- p.width(ow+dx);
- p.height(oh+dy);
- });
- });
本文介绍了一种使用jQuery实现元素拖拽的方法。通过定义handleDrag函数,并利用on_mousedown和on_mousemove回调来更新元素的位置。该方法允许开发者指定元素在鼠标按下和移动时的行为,实现了元素的动态调整。

1474

被折叠的 条评论
为什么被折叠?



