Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input field prevents page from scrolling on iphone

Im working on a site that has a lot of forms. I have noticed that when you scroll/swipe the site on an iphone the page does not scroll if your finger is on an input field. To scroll you have to aim your finger on the body kind of.

Anyone having some ideas on what causes this strange behaviour?

Its just simple inputs wrapped in a form tag.

like image 553
user3122094 Avatar asked Apr 05 '14 14:04

user3122094


People also ask

How do I get my iPhone to stop scrolling?

Given below are simple steps to reset all settings of your iPhone and get rid of the automatic scrolling issue: Step 1: Go to Setting in your iPhone. Step 2: Tap on the General option. Step 3: Click on Reset followed by Reset All Settings.

What is scroll down in iPhone?

Scroll. Move one finger across the screen without lifting. For example, in Photos, you can drag a list up or down to see more. Swipe to scroll quickly; touch the screen to stop scrolling.


1 Answers

A workaround for this issue might be :

function setTextareaPointerEvents(value) {
    var nodes = document.getElementsByTagName('textarea');
    for(var i = 0; i < nodes.length; i++) {
        nodes[i].style.pointerEvents = value;
    }
}

document.addEventListener('DOMContentLoaded', function() {
    setTextareaPointerEvents('none');
});

document.addEventListener('touchstart', function() {
    setTextareaPointerEvents('auto');
});

document.addEventListener('touchmove', function() {
    e.preventDefault();
    setTextareaPointerEvents('none');
});

document.addEventListener('touchend', function() {
    setTimeout(function() {
        setTextareaPointerEvents('none');
    }, 0);
});

This will make Mobile Safari (others not tested so far) ignore the textareas for scrolling but allows to set focus etc. as usual.

like image 170
Cristi Marian Avatar answered Oct 28 '22 05:10

Cristi Marian