jQuery Draggable 双击重置位置

发布于 2024-12-02 15:10:36 字数 163 浏览 3 评论 0原文

我对这个 jsfiddle 示例有点困惑。当用户拖动方块时,一切正常。但是,当用户将其拖离原始位置后双击该正方形时,我希望它返回到仅一半工作(垂直)的原始位置。它不会向右走! 非常感谢任何帮助:)

I am a bit stuck with this jsfiddle example. When the user drags the square that's all working fine. But when the user double clicks the square after dragging it away from the original position i want it to return to the original position which is only half working (vertically). It is not going to the right!
Any help much appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃梦幻 2024-12-09 15:10:36

你可以这样做(我纠正了你的小提琴,因为它完全错误):

jQuery("#drag_item").draggable({containment: '#container'});
var position = jQuery("#drag_item").position();
//you could also use 
//var position = jQuery("#drag_item").offset();

$("#drag_item").dblclick(function() {



    $('#drag_item').css({
        'top': position.top
    });

    $('#drag_item').css({
        'position': 'fixed'
    });
    $('#drag_item').css({
        'left': position.left
    });
});

在这里小提琴 http://jsfiddle.net/6kXTP /5/

you could do (i corrected your fiddle because it was totally wrong):

jQuery("#drag_item").draggable({containment: '#container'});
var position = jQuery("#drag_item").position();
//you could also use 
//var position = jQuery("#drag_item").offset();

$("#drag_item").dblclick(function() {



    $('#drag_item').css({
        'top': position.top
    });

    $('#drag_item').css({
        'position': 'fixed'
    });
    $('#drag_item').css({
        'left': position.left
    });
});

fiddle here http://jsfiddle.net/6kXTP/5/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文