Select2 v3.5在使用移动设备滑动/滚动时打开选择
Select2 v3.5 opens the select when swiping/scrolling using a mobile device
如果您使用移动设备或browserstack移动模拟器访问此页面
http://select2.github.io/select2/试着用指针(手指)指向select2框向下滚动页面,你开始从select2框上滑动,你会看到它打开了select2框。当它在滑动,而不是点击。
这里我设置了一个基本的相互依赖的例子
而如果您尝试在v4 Select2上做同样的事情,它将无法打开。
我无法迁移到v4.0并被迫使用这个旧版本的问题。
是否有任何方法可以防止打开select2框时,滑动(不点击)他们使用移动设备?
我也看了这个提交,并试图替换源代码,但它没有work
好的。由于我还没有找到解决这个问题的有效方法,我将发布我如何决定解决这个问题。
$(document).on("mousedown touchstart", ".select2-container", function(e) {
$('select').select2('close');
});
$(document).on("mousedown touchend", ".select2-container", function(e) {
$('select').select2('close');
});
当然不是那么漂亮和合理的工作,但工作在预期的
接受的答案使用mousedown
事件,当我们试图打开时,它使select2关闭为正常的非触摸(鼠标)事件。还添加了css("pointer-events", "none")
,使元素是可滚动的。
注意:
- 仍然有一个小光点在select2打开和关闭。
- select version - 3.5.1
- mousedown在IE和Safari中有兼容性问题
$('.select2-container').on("touchmove", function(e) {
$(this).css("pointer-events", "none");
$('select').select2("close");
})
$('.select2-container').on("touchstart", function(e) {
$(this).css("pointer-events", "auto");
});
Select2 Version: 3.5.1
删除"touchstart"
selection.on("mousedown", "abbr", this.bind(function (e) {
if (!this.isInterfaceEnabled()) return;
this.clear();
killEventImmediately(e);
this.close();
this.selection.focus();
}));
selection.on("mousedown", this.bind(function (e) {
// Prevent IE from generating a click event on the body
reinsertElement(selection);
if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus"));
}
if (this.opened()) {
this.close();
} else if (this.isInterfaceEnabled()) {
this.open();
e.preventDefault();
}
killEvent(e);
}));
相关文章:
- Firefox输入可以't在选择文本时滚动
- 在选择时停止纯CSS选项卡滚动到页面顶部
- 取消选择滚动启动时的所有列表视图项目
- 推特引导滚动间谍总是选择最后一个元素
- Google 图表 - 设置选择不会滚动到表格可视化中的选定行
- 在 IE 中从 DOM 中删除选项时,滚动选择元素会跳到顶部
- 选择/选项中的垂直滚动条
- 将引导程序下拉选择滚动条居中到所选项目
- jquery ui选择菜单滚动条不工作
- JavaScript-HTML<选择>单击滚动条的向下按钮时触发的onclick事件
- Extjs 4.2.1滚动到组合下拉列表中的选择
- 如何将鼠标选择默认效果转换为在网站中滚动/滑动
- 如何使用类选择器使用 Jquery ScrollTo() 将页面滚动到元素
- 根据滚动位置更新选择菜单中的选定选项
- IE <选择>滚动顶部
- 选择面板选项卡时滚动到锚标记
- removeattr滚动选择并添加atriv
- 使用向上/向下箭头滚动选择列表,但要关注输入元素
- Javascript滚动选择与收藏按钮
- 平滑滚动选择更改 jquery