我正在使用jquery ui draggable做拖动div。什么是阻力停止后平稳缓解阻力的最佳方法? 假设阻力突然停止。
谢谢
答案 0 :(得分:5)
使用缓动实现可拖动可能对您有用。这是我对前一个帖子的回答的简化解决方案,更具体:
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/