Skip to content

Instantly share code, notes, and snippets.

@pbakaus
Created December 29, 2010 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbakaus/758383 to your computer and use it in GitHub Desktop.
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..
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