このページを日本語で閲覧するには「続ける」を押してください。
Press "Continue" to see this page in English.
2023
 
Jun
 
27
 

How to Disable Scroll When Opening a Menu or Modal in Webflow

This article explains how to prevent background scrolling when opening a menu or modal in Webflow.

Shohei Yano

Hello everyone!
In this post, I’ll show you how to disable scrolling when opening a navigation menu or modal in Webflow.

This tutorial is also available in video format ⏬

Code to Disable Scrolling

$(document).ready(function() {
  $('.class-name').click(function() {
    $('body').toggleClass('overflow__hidden');
  });
});

Make sure to replace .class-name with the class name of your menu button.
Then, create a CSS class named overflow__hidden and apply overflow: hidden; to it.
When the menu closes, the class will be removed automatically.

How the Code Works

When the element with .class-name is clicked, the script toggles the overflow__hidden class on the <body> tag.
Adding overflow: hidden; to the body prevents the entire page from scrolling.

Troubleshooting

If the code doesn’t work, the most common issue is incorrect class naming.
For example, if the class name in Webflow Designer is Nav Button, you should write it as nav-button in your code.

Webflow automatically converts:

  • Uppercase → lowercase
  • Spaces → hyphens (-)

So always adjust the class name accordingly when writing code.

Summary

By simply adding a small piece of code, matching your class names, and applying some CSS, you can easily disable scrolling in Webflow.
While this can’t be done with Webflow’s default settings, a few lines of code make it possible.

I also share more about using Webflow, building websites with it, and the benefits of running your business site on Webflow.
If you have any questions or need advice, feel free to reach out anytime through the contact form!

Newsletter

Subscribe to updates

Signup for practical tips on growing your business online, useful updates and event info.

We respect your privacy and never send spam messages. You can unsubscribe anytime.

By sending this form you agree to Privacy Policy

送信しました。ありがとうございます。
送信中にエラーが発生しました。
Our customers

We help you grow on web

We are a web company based in Tokyo, Japan.

Our international team of web experts will help you solve any of your challenges.