简体   繁体   English

'jQuery UI Draggable' 防止点击可拖动容器内的元素

[英]'jQuery UI Draggable' prevents some clicks on elements inside the draggable container

I'm building a menu that's draggable horizontally:我正在构建一个可水平拖动的菜单:

https://i.imgur.com/XOTmtij.gif

The code is pretty straightforward, and the dragging works fine:代码非常简单,拖动效果很好:

$draggable.draggable({
   axis: "x",
   distance: 30,
   delay: 40,
   scroll: false
});

Here's the issue at a high level:这是高层次的问题:

  • With jQuery Draggable:使用jQuery 可拖动:

    https://i.imgur.com/FDcTmPx.gif

    Every time you see the mouse go from one button to the other, you can assume that I'm clicking.每次您从一个按钮到另一个按钮看到鼠标 go 时,您可以假设我在点击。 And as you can see, there are some clicks that are ignored/missed (the click callback is not called at all).如您所见,有一些点击被忽略/错过(根本不调用点击回调)。

  • Without jQuery Draggable带 jQuery 可拖动

    https://i.imgur.com/UYvArrn.gif

    You can see that no clicks are missed (and for some reason, there's this browser blue overlay that doesnt appear when jquery draggable is on, that might be part of the issue)您可以看到没有错过任何点击(由于某种原因,当 jquery 可拖动打开时,不会出现此浏览器蓝色叠加层,这可能是问题的一部分)


I tried to play with the distance and delay options of jQuery draggable but it doesn't seem to affect the issue in any way.我尝试使用 jQuery 可拖动的distancedelay选项,但它似乎不会以任何方式影响问题。

I also have a secondary issue that's probably related.我还有一个可能相关的次要问题。 On Android 9, on Chrome, you can barely click on the buttons at all.在 Android 9 上,在 Chrome 上,您几乎无法点击按钮。 It works when you click on the "padding" part, but not on the text itself, which is REALLY weird to me.当您单击“填充”部分时它可以工作,而不是文本本身,这对我来说真的很奇怪。 On iOS tho, it works fine.在 iOS 上,它工作正常。

https://i.imgur.com/AtHEEd2.png?1


Here's the mark-up in case it helps:这是标记以防万一:

https://i.imgur.com/SS3jP0S.png


Do you have any idea on why jQuery Draggable breaks the clicks on desktop and/or mobile?您知道为什么 jQuery Draggable 会破坏桌面和/或移动设备上的点击吗?

With 1.12, I can click and I can drag without distance .在 1.12 中,我可以单击并且可以无distance拖动。 See the following.请参阅以下内容。

 $(function() { $("#pills-container.draggable").draggable({ axis: "x", scroll: false, containment: [ 0 - ($(window).width() / 2), 0, $(window).width() + ($(window).width() / 2), 0 ] }); $("#pills-container.filter-pill").click(function() { $(this).toggleClass("ui-state-highlight"); }); });
 .draggable-container { width: 100%; padding: 0.4em; overflow: none; }.draggable-container.filter-pill { display: inline-block; padding: 0.5em 1em; border-width: 2px; border-color: transparent; border-radius: 20px; }.draggable-container.filter-pill.ui-state-highlight { border-width: 2px; }
 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div> <div id="pills-container" class="ui-widget"> <div class="draggable-container ui-widget-header"> <div class="draggable"> <div class="filter-pill mr-4 ui-widget-content">Location</div> <div class="filter-pill mr-4 ui-widget-content">Length</div> <div class="filter-pill mr-4 ui-widget-content">Interests</div> <div class="filter-pill mr-4 ui-widget-content">More</div> </div> </div> </div> </div>

I am testing with FireFox 84 (64-bit Linux).我正在使用 FireFox 84(64 位 Linux)进行测试。 If I drag a pill, it does catch the click too.如果我拖动一个药丸,它也会抓住点击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM