Any recommendations for resolving the issue with the overlay having "overflow: hidden;" rather than affecting the entire body?

My hamburger menu on the navbar should open a full-screen black overlay that is un-scrollable when clicked, but for some reason it's not working correctly. Any help would be greatly appreciated! Thanks!

$(function() {

  $(".menu-link").click(function(e) {
    e.preventDefault();

    $(".menu-overlay").toggleClass("open");
    $(".menu").toggleClass("open");

  });

});
.nav {
    display: flex;
    justify-content: space-between;
    padding: 0 5%;
}

#brandname {
    color: black;
    font-weight: bold;
    font-family: Circular Std Black;
    line-height: 60px;
    font-size:20px;
    margin-top: 45px;
}

.menu {
  position: absolute;
  margin-top: 50px;
  right: 5%;
  height: 46px;
  width: 46px;
}

.menu-link {
  width: 100%;
  height: 100%;
  position: absolute;
  z-index: 1002;
}

.menu-icon {
  position: absolute;
  width: 20px;
  height: 15px;
  margin: auto;
  left: 0;
  top: 0;
  right: 0;
  bottom: 1px;
}

/* ------------- */
.menu-line {
  background-color: white;
  height: 3px;
  width: 100%;
  border-radius: 2px;
  position: absolute;
  left: 0;
  transition: all 0.25s ease-in-out;
}
.menu-line-2 {
  top: 0;
  bottom: 0;
  margin: auto;
}
.menu-line-3 {
  bottom: 0;
}
.menu.open .menu-line-1 {
  transform: translateY(7px) translateY(-50%) rotate(-45deg);
}
.menu.open .menu-line-2 {
  opacity: 0;
}
.menu.open .menu-line-3 {
  transform: translateY(-7px) translateY(50%) rotate(45deg);
}

/* ------------- */
.menu-circle {
  background-color: #E095F0;
  width: 100%;
  height: 100%;
  position: absolute;
  border-radius: 50%;
  transform: scale(1);
  z-index: 1000;
  transition: transform 0.3s ease-in-out;
}
.menu:hover .menu-circle {
  transform: scale(1.5);
}
.menu.open .menu-circle {
  transform: scale(60);
}

/* ------------- */
.menu-overlay {
  background-color: black;
  color: white;
  height: 100%;
  width: 100%;
  position: fixed;
  transition: opacity 0.2s ease-in-out;
  z-index: 1001;
  opacity: 0;
  visibility: hidden;
  display: flex;
  flex-direction: column;
}
.menu-overlay.open {
  opacity: 1;
  visibility: visible;
}
<nav class="nav">
    <div id="brandname">Test</div>
    <div class="menu">
      <span class="menu-circle"></span>
      <a href="#" class="menu-link">
        <span class="menu-icon">
          <span class="menu-line menu-line-1"></span>
          <span class="menu-line menu-line-2"></span>
          <span class="menu-line menu-line-3"></span>
        </span>
      </a>
    </div>

    <div class="menu-overlay">
        <a href="#">Home</a>
        <a href="#">About</a>
    </div>


</nav>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Answer №1

Here are some tips for adjusting the CSS inline:

Avoid using Flexbox for the overlay itself. If you want to use Flexbox within the overlay, apply it to the elements inside.

If you're sizing the overlay with percentages, avoid placing it as a child of the main content in the HTML. Instead, utilize vh and vw units (Viewport Height and Viewport Width).

To position the overlay at the top-left corner of the screen, set the CSS properties top and left.

Instead of using visibility to hide the overlay, employ display:none to hide it and then display:block to show it again.

$(function() {

  $(".menu-link").click(function(e) {
    e.preventDefault();

    $(".menu-overlay").toggleClass("open");
    $(".menu").toggleClass("open");

  });

});
/* ------------- */
.menu-overlay {
  transition: opacity 0.2s ease-in-out;
  opacity:0;
  display:hidden;
}
.menu-overlay.open {
  position: fixed; 
  top:0;
  left:0;
  height: 100vh;
  width: 100vw;  
  
  opacity:1;
  display:block;
  z-index: 1001;  
  background-color: black;
  color: white;
}

.nav {
    display: flex;
    justify-content: space-between;
    padding: 0 5%;
}

#brandname {
    color: black;
    font-weight: bold;
    font-family: Circular Std Black;
    line-height: 60px;
    font-size:20px;
    margin-top: 45px;
}

.menu {
  position: absolute;
  margin-top: 50px;
  right: 5%;
  height: 46px;
  width: 46px;
}

.menu-link {
  width: 100%;
  height: 100%;
  position: absolute;
  z-index: 1002;
}

.menu-icon {
  position: absolute;
  width: 20px;
  height: 15px;
  margin: auto;
  left: 0;
  top: 0;
  right: 0;
  bottom: 1px;
}

/* ------------- */
.menu-line {
  background-color: white;
  height: 3px;
  width: 100%;
  border-radius: 2px;
  position: absolute;
  left: 0;
  transition: all 0.25s ease-in-out;
}
.menu-line-2 {
  top: 0;
  bottom: 0;
  margin: auto;
}
.menu-line-3 {
  bottom: 0;
}
.menu.open .menu-line-1 {
  transform: translateY(7px) translateY(-50%) rotate(-45deg);
}
.menu.open .menu-line-2 {
  opacity: 0;
}
.menu.open .menu-line-3 {
  transform: translateY(-7px) translateY(50%) rotate(45deg);
}

/* ------------- */
.menu-circle {
  background-color: #E095F0;
  width: 100%;
  height: 100%;
  position: absolute;
  border-radius: 50%;
  transform: scale(1);
  z-index: 1000;
  transition: transform 0.3s ease-in-out;
}
.menu:hover .menu-circle {
  transform: scale(1.5);
}
.menu.open .menu-circle {
  transform: scale(60);
}
<div class="menu-overlay">
  <a href="#">Home</a>
  <a href="#">About</a>
</div>
<nav class="nav">
    <div id="brandname">Test</div>
    <div class="menu">
      <span class="menu-circle"></span>
      <a href="#" class="menu-link">
        <span class="menu-icon">
          <span class="menu-line menu-line-1"></span>
          <span class="menu-line menu-line-2"></span>
          <span class="menu-line menu-line-3"></span>
        </span>
      </a>
    </div>
</nav>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Answer №2

Big shoutout to @Scott Marcus for helping with the layout issues, however the overflow problem was not fully resolved. I ended up adding a toggle-class function in JavaScript which seems to have fixed the issue. Let me know if you spot any potential DOM errors. Cheers!

$('.menu-link').click(function() {
  $('body').toggleClass('no-scroll');
});

.no-scroll{
    overflow: hidden;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Passport.js simply redirects to the failure page without invoking the LocalStrategy

I'm facing a persistent issue with Passport.js in my Express.js small application. No matter what I input in the LocalStrategy, I always end up being redirected to the failureRedirect without seemingly passing through the LocalStrategy at all. What am ...

What is the best way to add an image to a SVG placeholder?

This is all unfamiliar territory for me. I am experimenting with the Bootstrap template named "Carousel" as my starting point, utilizing Bootstrap 5.3.2. Here is the link to the Carousel example Everything seems fine so far. However, I am struggling to l ...

Troubleshooting Problem with NextJs Map

I'm struggling to properly map an array and keep encountering errors. Here is the array I need to map: useful_links: 0: {Register Now: 'some link'} 1:{Age Calculator: 'some link'} 2: {Join Now: 'some link'} 3:{Cantonment ...

Exploring the Differences Between setImmediate and nextTick

Today, a new version of Node.js (version 0.10) has been released, introducing the setImmediate feature. The API changes documentation recommends using it for recursive operations instead of nextTick. After checking what MDN says, it appears that setImmedi ...

Adding an image using Jquery to a particular set of coordinates

Is there a way to insert an image at the exact spot where a user clicks inside a div using jQuery? I am working on creating a simple game that requires users to click on the screen to guess a position - and have an image appear wherever they click... Whi ...

How to Customize a Jquery Mobile Panel

As I work on my first Jquery Mobile application, I have successfully implemented a panel for navigation. Inside the panel, I am using an unordered list (<ul><li>home</li><li>search</li><li>... etc</li></ul>) ...

Guide to passing table row information to a form input for editing in AngularJS

Can someone assist me with AngularJS code? I have a table with rows that contain an "Edit" button. When the edit button is clicked, I want the data from that row to be displayed in a form below for editing. How can I modify the AngularJS code to achieve th ...

What are some strategies for implementing a basic search function using arrays in JavaScript?

Is my approach to creating a search function using arrays instead of a database correct? <script type="text/javascript> $(document).ready(function() { $(document).on('submit', '#sample', function() { var inputs = docu ...

AngularJS allows users to seamlessly retain any entered form data when redirected, enabling users to pick up right where they left off when returning to the form

I am currently working on a user data collection project that involves filling out multiple forms. Each form has its own dedicated HTML page for personal details, educational details, and more. After entering personal details and clicking next, the data ...

As we iterate through each individual array within the multi-dimensional array

I'm currently working on an application using node.js, Express, and JS/Jquery. One issue I've encountered is with appending elements to a webpage based on the number of arrays contained in a MD array. Essentially, I only want to append unique e ...

Guide on: Reloading an AngularJS Route

I'm in the process of setting up a Typescript SPA project using Visual Studio and AngularJS for routing. Here is my current configuration... var app = angular.module("myApp", ["ngRoute"]); app.config(($routeProvider, $locationProvider) => { $route ...

obtain data from JSON using JavaScript

Greetings! I am dealing with a JSON output that looks like this: "{ \"max_output_watts\": 150, \"frame_length_inches\": \"62.20\", \"frame_width_inches\": \"31.81\" }" I am using it in a functi ...

What is the best way to obtain a unique result for a single cell without encountering any duplicates when using the Angular

Currently, I have functional code that successfully passes data from a dialog window to a table. Everything works fine for a single row, but when I try to add multiple rows to the table, I get results for several columns simultaneously. Is there a way to o ...

Emphasize certain VueJS elements for focus

Currently, I am working with a Vue file and I'm interested in highlighting the active element. Can you recommend the most efficient method to achieve this? <li @click = "selectedComponent = 'appBugs1'"><i class="ion-bug"></i& ...

What is the process for transforming a block of plain text into a formatted text with multiple paragraphs while tracking the word count

I am faced with the task of transforming a simple text consisting of 5000 words into multiple paragraphs, each containing 1000 words. Is there a way to accomplish this? If so, I would greatly appreciate any guidance or assistance you can provide. ...

Having difficulty getting CSSCount to function properly

After attempting to follow the steps outlined in this particular blog post in order to obtain a count of CSS locators, I encountered an issue with the method provided: public static int getCSSCount(String cssLocator) { String jsScript = "var cssMatche ...

Maintain the color of a Bootstrap 4 dropdown link even when it is open by incorporating hover

Currently, I am utilizing bootstrap 4 to create a menu that includes dropdown items. The issue I am facing is that when hovering over a dropdown link, the background color changes and the dropdown opens. However, as soon as I move the mouse to select one o ...

CoffeeScript:: I can't understand why the function body returns when using ajax

Hey there, I'm new to Coffeescript and have a question regarding Ajax. jQuery -> api = getId: -> res = [] $.ajax dataType: "jsonp" url: "http://localhost:3004/videos.json" success: (data) => ...

What is the most effective method for converting this flash application into a format that is compatible with

I have a unique flash animation that I want to make compatible with iPhones by integrating it into an iPhone app. Unfortunately, I cannot provide a direct link to the animation, but you can view a screenshot of the interface here. This interactive animat ...

What are some effective ways to display input text alongside input radio buttons?

Hello, I am trying to display an input with a radio button, but for some reason it is not working correctly. When I click on 'No' it shows the correct input, but when I click on 'Yes' nothing appears. I'm unsure why this is happeni ...