【问题标题】:JQuery droppable out event is not fired sometimes draggable with cursorAtJQuery droppable 事件不会被触发,有时可以用 cursorAt 拖动
【发布时间】:2016-08-19 12:05:23
【问题描述】:

当 draggable 具有参数 cursorAd 时,有时 JQuery droppable out 事件不会触发(在开始拖动之前,draggable 会从 droppable 中移出以设置光标位置,就像在 cursorAd 中一样)。

例如(尝试从右下角拖动):

<!doctype html>
<html lang="ru">
    <head>
        <meta charset="utf-8" />
        <script type="text/javascript" src="jquery.min-1.5.0.js"></script>
        <script type="text/javascript" src="jquery-ui.min-1.8.9.js"></script>
    </head>
    <body>
        <div id="dg1" style="z-index:1;border:1px solid red;width:100px;height:50px;position:absolute;">draggable</div>
        <div id="dp1" style="border:1px solid green;width:100px;height:50px;position:absolute; top:100px;left:100px;">droppable</div>
    <script>
        $(document).ready(function(){
            $('#dg1').draggable({
                cursorAt:{
                    left:20,
                    top:20
            }
        });
        $('#dp1').droppable({
            drop:function(){
                console.log('drop event');
            },
            out:function(){
                console.log('out event');
            }
        });
    });
    </script>
    </body>
</html>

请帮我解决这个问题

【问题讨论】:

    标签: javascript jquery jquery-ui draggable droppable


    【解决方案1】:

    只需将容差touch 添加到可丢弃

    tolerance:"touch"
    

    Working Demo

    默认情况下tolerance 设置为intersect

    "intersect"Draggable 与 droppable 在两者中至少重叠 50% 方向。

    我们需要根据您的要求将其设为touch

    “触摸”Draggable 与 droppable 重叠任意数量。

    【讨论】:

    • 更难从 droppable 中退出 draggable 而不触发具有容差的事件:"touch" 但问题没有解决
    • @Mikhail:drop 事件和 out 事件总是越来越多。现在是什么?你能解释一下你到底需要什么。
    • 首先像这张图片一样拖动可拖动oi66.tinypic.com/6qe7pi.jpg。在此操作后,将 droppable 放在右下角并尝试将其向右和向下移动。我想捕捉可拖动离开可放置的时刻。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-29
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    • 2013-06-22
    • 1970-01-01
    相关资源
    最近更新 更多