Skip to content

Instantly share code, notes, and snippets.

@whayler1
Last active April 18, 2018 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whayler1/9393501 to your computer and use it in GitHub Desktop.
Save whayler1/9393501 to your computer and use it in GitHub Desktop.
Fixes a bug where elements with "-webkit-overflow-scrolling: touch" stop scrolling on orientation change.
/**
* Fixes a bug where elements with "-webkit-overflow-scrolling: touch" stop
* scrolling on orientation change. If you have a shim for requestAnimationFrame
* it would be good to replace setTimeout with that, but I wanted to write this
* dependancy free.
*
* @author Justin Worsdale
*/
(function(document, window) {
// set scrollingElQuery to a class included on all your overflow-scrolling elements
var scrollingElQuery = '.scroll-pane',
timeout,
resetScrollPanes = function(e) {
var scrollingElements = document.querySelectorAll(scrollingElQuery),
i = 0;
/**
* Clear timeout so we do not have overlap if user changes orientations
* back and forth quickly.
*/
clearTimeout(timeout);
for( ; i < scrollingElements.length; i++) {
scrollingElements[i].setAttribute('style',
'-webkit-overflow-scrolling:auto;overflow:hidden;');
}
timeout = setTimeout(function() {
for( i = 0; i < scrollingElements.length; i++) {
scrollingElements[i].setAttribute('style',
'-webkit-overflow-scrolling:touch;overflow:auto;');
}
}, 10);
};
window.addEventListener('orientationchange', resetScrollPanes);
}(document, window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment