jQuery live scroll event on mobile (work around)

With jQuery:

$('body').bind('touchmove', function(e) { 
    console.log($(this).scrollTop()); // Replace this with your code.
});

This should give you a consistent stream of the scrollTop value when the user scrolls, but be careful as it’s going to fire even while the user is just holding his finger on the screen.

Note that if you’re using jQuery >= 1.7 the preferred binding method is
.on() instead of the .bind() method I’ve used in my example. In that case my example would be

$('body').on({
    'touchmove': function(e) { 
        console.log($(this).scrollTop()); // Replace this with your code.
    }
});

Source: https://github.com/dantipa/pull-to-refresh-js/blob/master/jquery.plugin.pullToRefresh.js

Leave a Comment