Why can't I click input?
Asked Answered
A

4

5

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. 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?

Americium answered 9/2, 2012 at 11:38 Comment(3)
Oddly enough right-clicking the input elements will move the focus to that element (even if you dismiss the context menu), but not clicking.Zahara
Yes, it works on right-click and label-click but not left-click also for me :)Americium
It might have something to do with your markup. You shouldn't nest an input inside a label tag. Is the markup dynamic? Maybe you should look into cutting down on the number of nested tags.Uneasy
H
12

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();
        }
   }
Hama answered 23/2, 2012 at 11:4 Comment(1)
WOOOOOOOOOO! +1 Thanks @Hama I hate to ask this of you, could you briefly explain why this worked :-/ If you get some time. Thanks again!Figurine
T
5
$('input[type=text]').bind('touchstart click', function(){
    $(this).focus();
});
Timekeeper answered 4/6, 2013 at 14:0 Comment(1)
Like most simple solutions, this one works best for me.Elodia
B
0
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);
Breen answered 3/7, 2014 at 19:7 Comment(0)
C
0

I use version 5.1.2 and it worked.

 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:/.*/ }
}
Chamorro answered 22/5, 2015 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.