jquery实现拖拽 本帖最后由 zhyb0807508205 于 2011-07-20 22:08:20 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考:http://www.cnblogs.com/ljchow/archive/2010/04/27/1721695.html 不是很适合我的需求,我要拖动的是几个Table,每个Table有id:11,12,21,22,31,32保存的位置使用Table的id 参考:http://jqueryui.com/demos/draggable/http://jqueryui.com/demos/droppable/ 参考:http://jqueryui.com/demos/draggable/http://jqueryui.com/demos/droppable/ //设置一个全局变量。var isDrag=false;//在被拖动目标上绑定 mousedown 事件,并且把 isDrag=true; this.dragStart=function (e) { isDrag=true; _cX=e.pageX; _cY=e.pageY; _dX=_cX-ThisO.offset().left; _dY=_cY-ThisO.offset().top; _pX=hide_panel.offset().left; _pY=hide_panel.offset().top; $(document).mousemove(This.dragMove); $(document).mouseup(This.dragStop); } //拖动中 this.dragMove=function (e) { if(_drag){ _cX=e.pageX; _cY=e.pageY; _tX=(_cX-_dX-_pX); _tY=(_cY-_dY-_pY); _nX=_cX-_dX-design_panel.offset().left; _nY=_cY-_dY-design_panel.offset().top; //以下部分代码为现在图片拖拽范围,请勿修改! if(_tX<=0-allow_ds){ _tX=0-allow_ds; _nX=0-allow_ds+ThisO.css('left'); } if(_tY<=0-allow_ds){ _tY=0-allow_ds; _nY=0-allow_ds+ThisO.css('top'); } if(_tX+ThisO.width()-allow_ds>=hide_panel.width()){ _tX=hide_panel.width()-ThisO.width()+allow_ds; _nX=design_panel.width()-ThisO.width()-ThisO.css('left')+allow_ds; } if(_tY+ThisO.height()-allow_ds>=hide_panel.height()){ _tY=hide_panel.height()-ThisO.height()+allow_ds; _nY=design_panel.height()-ThisO.height()+allow_ds; } ThisO.css({'left':_nX,'top':_nY}); if(options.mainFlag){ $(options.mainTag).css({'left':_tX,'top':_tY}); }else{ $(options.mainTag).css({'left':_nX,'top':_nY}); } } } //拖动结束 this.dragStop=function (e) { if(_drag){ _drag=false; _cX=e.pageX; _cY=e.pageY; _tX=(_cX-_dX-_pX); _tY=(_cY-_dY-_pY); $(document).unbind('mousemove'); $(document).unbind('mouseup'); options.finish(_tX,_tY); } } 用jquery-ui的draggable,有大量丰富的api,毕竟是官方给的 参照:http://www.cnblogs.com/jikey/archive/2010/08/23/1806059.html CKEditor功能扩展示例--为image对话框添加自己的upload按钮 window.opener.document 为空或不是对象 简单问题,希望大家帮忙看看 web开发中的滚动条,用什么方法可以监听它的事件? safari浏览器下如何使文本内容复制到剪切板? 使用Cookie缓存窗口对象的问题 求alert confirm prompt的详细用法 js复选框传值的问题? 如何在一个Iframe中调用别外一个Iframe中的标签?在线等待!!! 关于函数的回调 请问这句话的意思 js可以类似asp.net地址栏传参数吗?如何获取?
http://www.cnblogs.com/ljchow/archive/2010/04/27/1721695.html
保存的位置使用Table的id
http://jqueryui.com/demos/draggable/
http://jqueryui.com/demos/droppable/
http://jqueryui.com/demos/draggable/
http://jqueryui.com/demos/droppable/
var isDrag=false;
//在被拖动目标上绑定 mousedown 事件,并且把 isDrag=true;
this.dragStart=function (e) {
isDrag=true;
_cX=e.pageX;
_cY=e.pageY;
_dX=_cX-ThisO.offset().left;
_dY=_cY-ThisO.offset().top;
_pX=hide_panel.offset().left;
_pY=hide_panel.offset().top;
$(document).mousemove(This.dragMove);
$(document).mouseup(This.dragStop);
}
//拖动中 this.dragMove=function (e) {
if(_drag){
_cX=e.pageX;
_cY=e.pageY;
_tX=(_cX-_dX-_pX);
_tY=(_cY-_dY-_pY);
_nX=_cX-_dX-design_panel.offset().left;
_nY=_cY-_dY-design_panel.offset().top;
//以下部分代码为现在图片拖拽范围,请勿修改!
if(_tX<=0-allow_ds){
_tX=0-allow_ds;
_nX=0-allow_ds+ThisO.css('left');
}
if(_tY<=0-allow_ds){
_tY=0-allow_ds;
_nY=0-allow_ds+ThisO.css('top');
}
if(_tX+ThisO.width()-allow_ds>=hide_panel.width()){
_tX=hide_panel.width()-ThisO.width()+allow_ds;
_nX=design_panel.width()-ThisO.width()-ThisO.css('left')+allow_ds;
}
if(_tY+ThisO.height()-allow_ds>=hide_panel.height()){
_tY=hide_panel.height()-ThisO.height()+allow_ds;
_nY=design_panel.height()-ThisO.height()+allow_ds;
}
ThisO.css({'left':_nX,'top':_nY});
if(options.mainFlag){
$(options.mainTag).css({'left':_tX,'top':_tY});
}else{
$(options.mainTag).css({'left':_nX,'top':_nY});
}
}
}
//拖动结束
this.dragStop=function (e) {
if(_drag){
_drag=false;
_cX=e.pageX;
_cY=e.pageY;
_tX=(_cX-_dX-_pX);
_tY=(_cY-_dY-_pY);
$(document).unbind('mousemove');
$(document).unbind('mouseup');
options.finish(_tX,_tY);
}
}
http://www.cnblogs.com/jikey/archive/2010/08/23/1806059.html