question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] useDocumentOverflow - reactive and centralized document style overflow management

See original GitHub issue

Sometimes it’s useful to control document.documentElement.style.overflow programmatically.

For example - when you open modal window and want to disable document scroll

Usage examples:

const { hideOverflow, restoreOverflow } = useDocumentOverflow();

// enable overflow: hidden
hideOverflow();

// remove overflow property
restoreOverflow();

// control X/Y and choose documentElement
const { overflowX, overflowY } = useDocumentOverflow({ documentElement: document.body });

overflowX.value = 'auto';
overflowY.value = 'hidden';

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
revyhcommented, Jun 21, 2021

I’d like to add my 5 cents. overflow: hidden on a document.body is not enough for disabling document scroll. There are solutions, like https://github.com/willmcpo/body-scroll-lock that do it better. So in my opinion, it would be better to either integrate such solution to vueuse, or not make half-measures at all

upd: sorry, looks like I’ve duplicated #534, should read that first

1reaction
wheatjscommented, Oct 26, 2021

Going to close in favor of using a library like body-scroll-lock.

Read more comments on GitHub >

github_iconTop Results From Across the Web

overflow - CSS: Cascading Style Sheets - MDN Web Docs
The overflow CSS shorthand property sets the desired behavior for an element's overflow — i.e. when an element's content is too big to...
Read more >
How to remove jank from overflow:hidden?
This is done with two simple functions I set in my Javascript. function hidden() { document.querySelector("body").style ...
Read more >
HTML DOM Style overflow Property - W3Schools
Tip: If you want to hide the scrollbars of the entire document, use the overflow property on the body or the html element....
Read more >
vueuse - bytemeta
[feature]: createEventHook: new function. cawa-93 ... [feature] useDocumentOverflow - reactive and centralized document style overflow management.
Read more >
CSS Overflow Module Level 3 - W3C
This module contains the features of CSS relating to scrollable ... to control the presence of scrollbars provided by the overflow property.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found