Question

I'm trying to prevent vertical scrolling in a page shown inside an app. I'm looking to use Hammer JS, but I'm not sure how should I use it. I've tried several events using event.preventDefault() but it doesn't seem to work.

For example:

    $(document).hammer().on('swipeup', 'body',
        function(event)
        {
            event.preventDefault();
        }
    );

Any ideas?

Was it helpful?

Solution

I don't know if using Hammer JS is a requirement for you but I've had success implementing horizontal scrolling (and disabling vertical scrolling) in iOS with iScroll 4 https://github.com/cubiq/iscroll (Examples here: http://cubiq.org/iscroll-4)

When you invoke iScroll, in the options pass hScroll: true and vScroll: false, like so:

new iScroll('XYZ', { hScroll: true, vScroll: false });

OTHER TIPS

I couldn't get it to work solely with Hammer calls, but adding this should work:

$(document).addEventListener("touchmove", function (e) { 
    e.preventDefault(); 
}, false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top