2011-07-06 69 views
2

我正在使用jQuery UI拖動做一個div的拖動。什麼是拖動停止後順利減輕拖動的最佳方式?假定拖動突然停止,則爲 。jquery ui可拖動減速停止

謝謝

回答

5

用easing實現拖動可能適用於你。這是我的回答一個簡單的解決方案,以前的線程,這是更爲具體:

JQuery draggable with ease

HTML:

<div id="draggable"> 
</div> 

CSS:

#draggable { 
    position: relative; 
    width: 100px; 
    height: 100px; 
    background-color: whitesmoke; 
    border: 2px solid silver; 
} 

的Javascript:

$(function() { 
    $("#draggable").draggable({ 
     helper: function(){ 
      // Create an invisible div as the helper. It will move and 
      // follow the cursor as usual. 
      return $('<div></div>').css('opacity',0); 
     }, 
     drag: function(event, ui){ 
      // During dragging, animate the original object to 
      // follow the invisible helper with custom easing. 
      var p = ui.helper.position(); 
      $(this).stop().animate({ 
       top: p.top, 
       left: p.left 
      },1000,'easeOutCirc'); 
     } 
    }); 
}); 

jsFiddle演示:http://jsfiddle.net/NJwER/26/

+0

'位置:相對;'在CSS是至關重要的,需要一段時間來捕捉! –

+0

偉大的解決方案 - 簡單,易於理解和有效。 –