2012-06-13 61 views
0

我已啓用在我的網頁上拖放表格行(代碼如下)。不幸的是,當我使用{ revert: invalid }該行返回到它的原始位置,但有一個輕微的偏移量。它看起來大約在5px左右。當我克隆整個表格行時,這看起來很奇怪。任何人都可以提供任何理由爲什麼?jQuery UI Draggable:不會恢復到原始位置

function setupDragDrop(source, target) { 
    source.draggable({ 
     revert: 'invalid', 
     opacity: 0.9, 
     cursor: 'move', 
     helper: function(event) { 
      var target = $(event.target).closest('tr'); 
      var target_children = target.children(); 

      var clone = target.clone(); 

      clone.children().width(function(i,val) { 
       return target_children.eq(i).width(); 
      }); 

      return $('<div class="configbox drag-row"><table class="lanes"></table></div>') 
       .find('table').append(clone).end(); 
     }, 
     start : function() { 
      //this.style.display="none"; 
     }, 
     stop: function() { 
      //this.style.display=""; 
     }, 
     appendTo: 'body' 
    }); 

    target.droppable({ 
     drop: function(event, ui) { 
      $(this).parent().append(ui.draggable); 
     }, 
     accept: source.selector 
    }); 
} 

回答

0

由於周圍的工作我已經改變了還原功能來改變原來的起始位置,以佔怪異的偏移,像這樣:

revert: function (event, ui) { 
    //overwrite original position 
    $(this).data("draggable").originalPosition = { 
     top: $(this).data("draggable").originalPosition.top - 9, 
     left: $(this).data("draggable").originalPosition.left - 9 
    }; 
    return !event; 
}, 
相關問題