简体   繁体   English

单击拖动时防止关闭引导下拉列表

[英]Prevent bootstrap dropdown from closing when clicked on drag

I got a dropdown with a fancy scroll in it. 我有一个带有花式卷轴的下拉菜单。 Fancy Scroll is a really simple library that replaces the default scroll. Fancy Scroll是一个非常简单的库,它取代了默认的滚动。 And just by adding some HTML markup, the scroll works without even having to initialize it using javascript. 只需添加一些HTML标记,滚动就可以使用javascript进行初始化。

After debugging to see what was going on, I found that bootstrap is making my dropdown hide when clicking on the drag. 经过调试以查看发生了什么后,我发现引导程序在单击拖动时隐藏了我的下拉列表。

The event is ' hide.bs.dropdown '. 事件是' hide.bs.dropdown '。

By now, I have attempted so many things, managed to make it work, but the only problem is, whenever I start dragging, due to the stopPropagation() function, it will keep scrolling nan-stap even though I released the mouse click. 到目前为止,我已经尝试了很多东西,设法让它工作,但唯一的问题是,每当我开始拖动时,由于stopPropagation()函数,即使我发布鼠标点击它也会继续滚动nan-stap。

These are a few things I've tried while googling, thing is, none of the solved answers involved this case scenario, having a scrollbar in it: 这些是我在谷歌搜索时尝试过的一些事情,事实上,这个案例场景中没有一个已解决的答案,其中有一个滚动条:

      $('.dropdown-menu input, .dropdown-menu label, .thumb', element).click(function(e) {
        e.preventDefault();
        e.stopPropagation();
      });

      $('.thumb', element).on('mouseup', function(e) {
         e.preventDefault();
         e.stopImmediatePropagation();
         return false;
      });

      $('.dropdown-menu .scrollbarY', element).click(function(e) {
        e.stopImmediatePropagation();
      });

      $(element).on("hide.bs.dropdown",function(e) {
        e.preventDefault();
        return false;
      });

The behavior I'm looking for is, clicking on the scroll drag (.thumb) wouldn't close the dropdown, but if there's a click on one of the items or away from dropdown, it should close it. 我正在寻找的行为是,单击滚动拖动(.thumb)不会关闭下拉列表,但如果点击其中一个项目或远离下拉列表,则应关闭它。

Okay, after a few more hours of struggling, a combination of the tests I made, solved the issue. 好吧,经过几个小时的挣扎,我所做的测试相结合,解决了这个问题。 If anyone encounters the same problem, here's what I did: 如果有人遇到同样的问题,这就是我做的:

(scrollbarY is the draggy parent) (scrollbarY是拖拉的父级)

      $('.scrollbarY', element).click(function(e) {
        e.preventDefault();
        e.stopImmediatePropagation();
        return false;
      });

Hope it works for everyone. 希望它适合每个人。

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

相关问题 单击时引导程序下拉关闭 - Bootstrap dropdown closing when clicked 单击链接时如何防止此下拉菜单关闭? - How do I prevent this dropdown from closing when link is clicked? 单击时关闭的下拉菜单中的引导程序选项卡 - bootstrap tabs inside a dropdown closing when clicked 防止在单击菜单项本身以外的其他位置时关闭引导程序下拉菜单 - Prevent bootstrap dropdown closing when clicked anywhere else other than the menu item itself 在下拉清单之外单击时如何关闭下拉清单,但在选择textarea时如何防止关闭它? - How to close dropdown checklist when clicked outside of it but prevent it from closing when textarea is selected? 需要停止传播以防止在单击下拉内容时关闭菜单 - Need to stop propagation in order to prevent menu from closing when clicked inside dropdown content React bootstrap 防止下拉菜单在下拉项目选择时关闭 - React bootstrap prevent dropdown menu from closing on dropdown item select 当用户从下拉菜单中选择项目时,如何防止引导程序模式关闭 - How to prevent a bootstrap modal from closing when user selects item from dropdown-menu Bootstrap,如何防止显示模式弹出窗口时关闭下拉菜单 - Bootstrap, how to prevent from closing a dropdown-menu when modal popup displayed 防止Bootstrap下拉菜单崩溃,直到单击按钮为止 - Prevent Bootstrap dropdown from collapsing until button is clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM