Skip to content

Instantly share code, notes, and snippets.

@daveespionage
Created September 20, 2012 11:10
Show Gist options
  • Save daveespionage/3755267 to your computer and use it in GitHub Desktop.
Save daveespionage/3755267 to your computer and use it in GitHub Desktop.
Force Scroll to Top in Javascript for Touch/Mobile
/*global pageYOffset:false */
/*=========== Force Scroll to Top ===========*/
var userHasNotScrolled = true;
$(window).on('touchmove', function(e) {
userHasNotScrolled = false;
});
if(/mobi/i.test(navigator.userAgent) && !location.hash)
{
setTimeout(function () {
if (!pageYOffset && userHasNotScrolled)
{
window.scrollTo(0, 1);
}
}, 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment