[英]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.