Last active
August 30, 2021 17:37
-
-
Save digitalicarus/c83d9b4c80ab35f7452a to your computer and use it in GitHub Desktop.
Chrome overflow problem
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
/** | |
* 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