Created
September 20, 2012 11:10
-
-
Save daveespionage/3755267 to your computer and use it in GitHub Desktop.
Force Scroll to Top in Javascript for Touch/Mobile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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