I\'m using the scrollTo jQuery plugin and would like to know if it is somehow possible to temporarily disable scrolling on the window element through Javascript? The reason
No, I wouldn't go with event handling because:
not all events are guaranteed to reach body,
selecting text and moving downwards actually scrolls the document,
if at the phase of event detaching sth goes wrong you are doomed.
I've bitten by this by making a copy-paste action with a hidden textarea and guess what, the page scroll whenever I make copy because internally I have to select the textarea before I call document.execCommand('copy')
.
Anyway that's the way I go, notice the setTimeout()
:
document.body.setAttribute('style','overflow:hidden;');
// do your thing...
setTimeout(function(){document.body.setAttribute('style','overflow:visible;');}, 500);
A momentum flashing exists as the scrollbars disappear momentarily but it's acceptable I thing.