[英]Why can't I click input?
I'm using iScroll4 plugin ( http://cubiq.org/iscroll-4/ ) to add scrollbar to pages that are longer than 80% of height of the browser's viewport. 我正在使用iScroll4插件( http://cubiq.org/iscroll-4/ )将滚动条添加到长度超过浏览器视口高度80%的页面。 For some reason when (and only in this case) I add it and try to click on input, it won't select. 出于某种原因,当(并且仅在这种情况下)我添加它并尝试点击输入时,它将不会选择。 Only clicking on its label will select input. 只需单击其标签即可选择输入。
What can I do to have iScroll4 and selectable input? 我该怎么做才能拥有iScroll4和可选择的输入?
Try this solution 试试这个解决方案
myScroll = new iScroll('wrapper', {});
myScroll.options.onBeforeScrollStart = function(e) {
var target = e.target;
while (target.nodeType != 1) target = target.parentNode;
if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA'){
e.preventDefault();
}
}
$('input[type=text]').bind('touchstart click', function(){
$(this).focus();
});
var myScroll;
function loaded() {
myScroll = new iScroll('wrapper', { scrollbarClass: 'myScrollbar' });
myScroll.options.onBeforeScrollStart = function(e) {
var target = e.target;
while (target.nodeType != 1) target = target.parentNode;
if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA'){
e.preventDefault();
}
}
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
I use version 5.1.2 and it worked. 我使用的是5.1.2版,但它确实有效。
window.myScroll = new IScroll ('#iscroll-wrapper',
probeType: 3,
mouseWheel: true,
scrollbars: true,
bounce: true,
keyBindings: true,
invertWheelDirection: false,
momentum: true,
fadeScrollbars: false,
interactiveScrollbars: true,
resizeScrollbars: true,
shrinkScrollbars: false,
click: false,
preventDefaultException: { tagName:/.*/ }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.