1
A
回答
1
您不能使用常規的可回收方法來獲取自定義返回緩動,因爲它只支持更改持續時間。如果您想使恢復具有自定義效果,您需要下面的一些自定義代碼,並插入來自JQueryUI展示http://jqueryui.com/demos/effect/#easing的任何自定義緩動效果。
請注意,在stop方法中,我使用easeInElastic來緩解效果,以突出區別,但您可以將其更改爲任何您想要的(線性的)。
請注意,您需要包含JQuery UI才能獲得這些效果。
http://jsfiddle.net/gregjuva/Hjf8p/
$(function() {
$("#draggable").draggable({
// We Can't use revert, as we animate the original object so
//revert: true, <- don't use this
helper: function(){
// Create an invisible div as the helper. It will move and
// follow the cursor as usual.
return $('<div></div>').css('opacity',0);
},
create: function(){
// When the draggable is created, save its starting
// position into a data attribute, so we know where we
// need to revert to.
// cache $this to keep from having to make
// lots of DOM calls w jquery
var $this = $(this);
$this.data('starttop',$this.position().top)
.data('startleft',$this.position().left);
},
stop: function(){
// When dragging stops, revert the draggable to its
// original starting position.
var $this = $(this);
$this.stop().animate({
top: $this.data('starttop'),
left:$this.data('startleft')
},1000,'easeInElastic');
// replace with whatever jQueryUI easing you want
},
drag: function(event, ui){
// During dragging, animate the original object to
// follow the invisible helper with custom easing.
$(this).stop().animate({
top: ui.helper.position().top,
left: ui.helper.position().left
},0,'linear');
}
});
});
相關問題
- 1. jQuery UI可拖動的第二個拖動不會恢復
- 2. jQuery UI可拖動回覆
- 3. jQuery的可拖動 - 移動拖,而不是重複
- 4. JQuery UI:可拖動不能恢復到原始位置
- 5. jquery-ui可拖動和動態的jquery-ui可拖動嗎?
- 6. jquery拖放 - 恢復當前
- 7. 使用jQuery。不是()和拖動UI
- 8. jQuery UI的可拖動:不是容器
- 9. jquery UI可拖動:ui.children不是函數
- 10. 當拖動一個類時拖動類的所有元素(jQuery UI可拖動)
- 11. jquery ui恢復刪除可拖動取消模式
- 12. 不能使jQuery UI元素可拖動?
- 13. 恢復融合爲使用jQuery可拖動/可棄
- 14. 如何在恢復時使可拖動元素不可見?
- 15. JQuery UI可拖動與Wijmo拖動
- 16. jQuery UI可排序/可拖動 - 使用調色板(複製/刪除而不是移動)
- 17. 當jQuery UI可拖動元素被恢復到原始位置時,是否有一個事件被調用?
- 18. JQuery-ui:元素失去「可拖動性」
- 19. jQuery UI的可拖動屬性
- 20. 使用GoogleAPI的jQuery UI可拖動
- 21. 如何使用jQuery可拖動事件拖動鏈條而不影響鐘擺運動
- 22. 拖動的iFrame使用jQuery UI可拖動
- 23. jQuery UI可拖動限制
- 24. jQuery UI可拖動網格
- 25. JQuery UI可拖動標籤
- 26. Jquery-ui拖放:不止一次使用可拖動
- 27. jquery ui可拖動滾動自動
- 28. jQuery UI可拖動事件時序
- 29. 當使用ajax內容刷新時,jQuery UI可拖動不會注入
- 30. 在jQuery UI中拖延後拖動拖動而不必移動鼠標?