Created
March 20, 2017 11:23
-
-
Save yy-dev7/7ef5c8065c904c560d8aa3201d2c5fd1 to your computer and use it in GitHub Desktop.
ScrollFix
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
/** | |
* ScrollFix v0.1 | |
* http://www.joelambert.co.uk | |
* | |
* Copyright 2011, Joe Lambert. | |
* Free to use under the MIT license. | |
* http://www.opensource.org/licenses/mit-license.php | |
*/ | |
var ScrollFix = function(elem) { | |
// Variables to track inputs | |
var startY, startTopScroll; | |
elem = elem || document.querySelector(elem); | |
// If there is no element, then do nothing | |
if(!elem) | |
return; | |
// Handle the start of interactions | |
elem.addEventListener('touchstart', function(event){ | |
startY = event.touches[0].pageY; | |
startTopScroll = elem.scrollTop; | |
if(startTopScroll <= 0) | |
elem.scrollTop = 1; | |
if(startTopScroll + elem.offsetHeight >= elem.scrollHeight) | |
elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1; | |
}, false); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment