Skip to content

Instantly share code, notes, and snippets.

@digitalicarus
Last active August 30, 2021 17:37
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 digitalicarus/c83d9b4c80ab35f7452a to your computer and use it in GitHub Desktop.
Save digitalicarus/c83d9b4c80ab35f7452a to your computer and use it in GitHub Desktop.
Chrome overflow problem
/**
* There's a nasty bug in Chrome for Windows where at times overflow auto isn't honored on
* a transitioned element after the transition. There is a workaround. Anything that forces
* a CSS recalc on that overflowed node will resume expected wheel / gesture scroll
* behavior.
* https://code.google.com/p/chromium/issues/detail?id=524687
* https://code.google.com/p/chromium/issues/detail?id=417345
*/
function forceCSSRecalc (rootNode) {
var firstOverflowEle = document.createTreeWalker(
rootNode,
NodeFilter.SHOW_ELEMENT,
function (node) {
var cs = getComputedStyle(node);
return cs.overflow === 'auto' || cs.overflowY === 'auto' ?
NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
})
.nextNode();
firstOverflowEle && (function () {
var t = document.createElement('span');
t.style.cssText &&
(t.style.cssText = 'font-size: 0; width: 1px; height: 1px; position: absolute; left: -9999px;');
firstOverflowEle.appendChild(t);
setTimeout(function() { firstOverflowEle.removeChild(t); }, 50);
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment