Prevent Body Scroll on Click

Prevent Body Scroll on Click

When clicking something lock the scroll of <body> if it isn’t already locked (set to overflow: hidden;). This is useful for things like opening modals, a mobile nav, etc. to ensure the user doesn’t have two levels of scrolling occurring at once.

Update the classes of .nav-button and .nav-overlay in the snippet below with the class you use on the mobile menu button and an overlay div that covers the rest of the screen if needed when the mobile menu is open. If you don’t have a separate overlay div, you can also target the native one that is part of the native Nav element in Webflow, which has the class of .w-nav-overlay.

Have feedback or a question related to this item? Drop us some feedback!

Curated: 
2.11.22

Similar items

Items
2777
Search

Click Something Based on ID in URL

8.27.20

Pause/Reset Video Embed on Click

8.17.20

Add to Calendar Button

8.12.20

Show a Preloader Only Once Per Day

1.3.24

Email Address Input Validation

12.15.23

Restock

View Restock

Remove https:// From Text Link

9.5.23

Run Javascript on Mobile Only

7.26.23

Skip to Main Nav Link

6.14.23

Randomize Button Text on Click

1.12.23

Get Website Meta Data w/ Airtable Script

1.10.23

Get YouTube Thumbnails w/ Airtable Script

12.22.22

Compress Images w/ Airtable Script

10.10.22

Get Image Size w/ Airtable Script

10.10.22

Simple Countdown to Date/Time

10.6.22

CSS Logo Marquee / Ticker

5.25.22

Birthday Age Gate Modal Overlay

5.10.22

View All or Show Less List Pagination

4.11.22

Set Referrer URL as Hidden Input

3.28.22

Fetch and Nest Content From Another Page

3.17.22

Set Text From URL Parameters

2.19.22

Round Number to Nearest Integer

2.19.22

Add Commas to Numbers

2.19.22

Simple Countdown Timer in Seconds

12.1.21

Bummer, no results

Try a different search/filter combo, or drop us some feedback if there is something missing you would love to see!

Reset filters

Subscribe for updates

Get updates on the latest curated resources and be the first to hear of new features.

Subscribe