jQuery拖拽移动

淡淡的烟草味﹌ 2022-08-03 15:52 293阅读 0赞

jquery sortable
它所有的事件回调函数都有两个参数:event和ui
ui.helper - 表示sortable元素的JQuery对象,通常是当前元素的克隆对象
ui.position - 表示相对当前对象,鼠标的坐标值对象{top,left}
ui.offset - 表示相对于当前页面,鼠标的坐标值对象{top,left}
ui.item - 表示当前拖拽的元素
ui.placeholder - 占位符(如果有定义的话)
ui.sender - 当前拖拽元素的所属sortable对象(仅当元素是从另一个sortable对象传递过来时有用)3

实例:拖动tbody中的tr

  1. function doRefresh() {
  2. window.location.reload();
  3. }
  4. $(function(){
  5. var changed = false;
  6. $("tbody").sortable({
  7. opacity: 0.5,//拖动的透明度
  8. revert: true, //缓冲效果
  9. cursor: 'move', //拖动的时候鼠标样式
  10. start:function(event, ui){
  11. if(navigator.userAgent.toLowerCase().match(/firefox/)&&ui.helper!=undefined){
  12. ui.helper.css('position','absolute').css('mergin-top',$(window).scrollTop());
  13. //当滚动条滚动时关联事件
  14. $(window).bind('scroll.sortableplaylist',function(){
  15. ui.helper.css('position','absolute').css('mergin-top',$(window).scrollTop());
  16. });
  17. }
  18. },
  19. beforeStop:function(event, ui){
  20. $(window).bind('scroll.sortableplaylist',function(){
  21. ui.helper.css('position','absolute').css('mergin-top',0);
  22. });
  23. },
  24. helper:function(e,ui){
  25. //设置拖动时辅助显示帮助
  26. ui.children().each(function(){
  27. $(this).width($(this).width());
  28. });
  29. return ui;
  30. },
  31. scroller:true,
  32. change : function(event,ui){
  33. changed = true;
  34. },
  35. stop:function(event,ui){
  36. //允许滚动显示
  37. //在拖动排序停止时可以保存排序
  38. if(changed){
  39. var currObj = ui.item;
  40. var currId = currObj.attr("id");
  41. var prevId = currObj.prev().attr("id");
  42. var nextId = currObj.next().attr("id");
  43. if(undefined==prevId){
  44. prevId=0;
  45. }
  46. if(undefined==nextId){
  47. nextId=0;
  48. }
  49. $.post(ROOT_PATH+"questions/question/"+currId+"/order",{prevId:prevId,nextId:nextId},function(data){
  50. if(data==1){
  51. doRefresh();
  52. }
  53. });
  54. }
  55. }
  56. }).disableSelection();
  57. });

发表评论

表情:
评论列表 (有 0 条评论,293人围观)

还没有评论,来说两句吧...

相关阅读

    相关 jQuery实现面板

    一.实现功能 1.首先页面有一个面板或者对话框,有长和宽,可以设置为一个div。 2.当把鼠标over到div的某个位置时,鼠标的箭头图片变为一个拖拽的图片。 3.接