在这里苦苦挣扎,我在 div 上使用 .draggable ,效果很好,但我还需要一个链接,以便一旦用户将 div 拖动到页面上的任何位置,他们就可以将其“重置”回原始位置。
$(function() {
if (! /iphone|ipad|ipod|android|blackberry/i.test(navigator.userAgent.toLowerCase())) {
$( "#race_charts_container" ).draggable({ revert: false, cancel: "#graphs_content"});
}
});
$("#btnReset").click(function() {
$("#race_charts_container").animate({
left: '+=50px',
top: '+=50px'
});
});
最佳答案
看看这个演示: http://jsfiddle.net/M8Ehe/1/
只需将顶部和左侧设置为 0。
代码:
$(function() {
if (! /iphone|ipad|ipod|android|blackberry/i.test(navigator.userAgent.toLowerCase())) {
$( "#race_charts_container" ).draggable({ revert: false, cancel: "#graphs_content"});
}
});
$("#btnReset").click(function() {
$("#race_charts_container").animate({left:0,top:0});
});
关于jquery - 单击链接后.draggable 恢复到原始位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10834214/