Search code examples
androidcordovaiscroll4

iscroll is not working properly for dynamic form in phonegap


I have developed android phonegap app.I have a appended the dynamic form contains 'input' and 'select' in the div.I need to get scrollbar for that div.So i used iScroll.js but its not working properly.While typing in the textbox suddenly scrollbar disappears.This problem occurring often.

Here is my code:

function loaded() 
{
    var myScroll = new iScroll('wrapper', 
    {
        scrollbarClass: 'myScrollbar',
        useTransform: false,
        vScroll: true,
        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);

Please kindly guide me.Thanks in Advance


Solution

  • so a couple of things that will be helpful - define your myScroll variable outside of your loaded function that way you can access it anywhere.

    also after your content has loaded call myScroll.refresh() and have at least a 1ms delay on it. little hack that goes a long way.