Created
December 29, 2010 10:00
-
-
Save pbakaus/758383 to your computer and use it in GitHub Desktop.
this little function determines the top scrolling element on the page on any device..
This file contains hidden or 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
function determineScrollingElement(callback) { | |
var self = this; | |
var div = $("<div style='height: 10000px;'></div>").appendTo(document.body); | |
var interval = window.setInterval(function() { | |
document.body.scrollTop = 50; | |
document.documentElement.scrollTop = 100; | |
if(window.pageYOffset != 0 || document.body.scrollTop != 0) { // finally, scrolling conditions are good if this attribute is non-zero | |
clearInterval(interval); | |
if(window.pageYOffset == 0) // this is likely a Palm Pre 2 or something like it | |
self.pageOffsetNotSupported = true; | |
if(document.body.scrollTop > 0) | |
self.scrollingElement = document.body; | |
if(document.documentElement.scrollTop > 0) | |
self.scrollingElement = document.documentElement; | |
if(!document.body.scrollTop && !document.documentElement.scrollTop) | |
self.scrollingElement = document.body; // holy crap it's an iPhone...doesn't allow you to read scrollTop, but set | |
document.body.scrollTop = 0; | |
document.documentElement.scrollTop = 0; | |
div.remove(); | |
callback.call(self); | |
} | |
}, 13); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment