【问题标题】:jQuery UI tooltip is stuck open when the source DOM element moves源 DOM 元素移动时,jQuery UI 工具提示卡在打开状态
【发布时间】:2015-01-28 09:12:44
【问题描述】:

我有一个 div,其中包含一些可以拖放的缩略图。当一个缩略图放在另一个缩略图之上时,它们会交换位置。我使用 AngularJS 并在 $scope 上操作底层数据。

不管怎样,问题来了:

当我将鼠标悬停在缩略图上时,它们会打开工具提示。当我单击并开始拖动缩略图(我们称其为源缩略图)时,它的工具提示会消失(应该如此)。到目前为止,一切都很好。但是,当我将缩略图放在另一个上方时,target 缩略图的工具提示会出现一小会儿,因为鼠标当前悬停在目标工具提示上。

一瞬间,底层模型交换了两条数据,并且 DOM 更新以反映更改 - 有效地交换了两个缩略图。现在,目标的工具提示仍然打开,但我的鼠标不再位于目标上方,因为它刚刚被交换!工具提示将保持打开状态,直到我在新位置重新触发工具提示事件。

这种行为在大约 50% 的时间内被观察到,但我可以通过在更改基础数据之前添加一个短暂(约 1 秒)的延迟来人为地在 100% 的时间内重现它,从而导致缩略图切换位置。

注意:这个问题在 Chrome 中不会出现,但在 Firefox 和 IE 中会出现。我没试过 Safari。

有没有人遇到过这个问题,或者类似的问题?如果我能提供任何进一步的细节,请告诉我。谢谢!

编辑:这是一个说明问题的 jsfiddle 示例:jsfiddle

<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
    <script>
        $.widget.bridge('uitooltip', $.ui.tooltip);
    </script>

<div ng-app="myApp">
    <div ng-controller="ContentController">
        <div class="indent">
            <div ng-repeat="square in squares" style="width: 400px">
                <item data="square" helper="helperFunction"></item>
            </div>
            Drag the top box onto the bottom box and keep the mouse cursor stationary for ~1 second.  The tooltip will be stuck open when the boxes switch places.  Dragging the bottom box to the top box, however, does not have this problem.
            <br><br>
            Also, this problem seems to only be present in Firefox and IE.  Chrome works as expected.
        </div>
    </div>
</div>

【问题讨论】:

    标签: javascript jquery angularjs jquery-ui jquery-ui-tooltip


    【解决方案1】:

    您可以将默认浏览器工具提示替换为 jquery 版本:

    $('*').tooltip({track: true});
    

    然后您可以在拖动元素时将工具提示设置为禁用:

    $('.thumbnail').tooltip('disable');
    

    在放置时,再次启用它们:

    $('.thumbnail').tooltip('enable');
    

    http://jsfiddle.net/uHuDp/1/

    编辑:以您为例:

     $(element).find("span.item-outer").uitooltip('disable');
     $(element).find("span.item-outer").uitooltip('enable');
    

    http://jsfiddle.net/uHuDp/260/

    【讨论】:

    • 我不太确定我是否在这里关注你。这是我所描述的一个活生生的例子:jsfiddle.net/uHuDp/257
    • 虽然您的更改似乎可以解决人为设计的 jsfiddle 示例中的行为,但它并不能解决我实际代码中的问题。如果您执行以下操作,仍然有可能破坏您的 jsfiddle 修复:将底部方块拖到顶部方块上,然后在有机会交换之前再次快速将鼠标移回底部方块。工具提示仍处于打开状态。这不是我在代码中遇到的确切问题,但我相信它是切线相关的。我不禁想知道这个问题是否与 Firefox 如何解决多个事件的顺序有关......
    猜你喜欢
    • 2020-01-10
    • 2012-10-14
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    相关资源
    最近更新 更多