Covering the page with a mask when the menu is activated

I'm currently facing an issue with my script. I am trying to implement a mask/filter over the website when the menu is opened. Within the HTML, there is a class named cmask and another called cmask is-active. This functionality should only take effect when the screen width is less than 900px. I have attempted to use cmask.addClass("is-active") and removeClass but it seems that this approach is not working as intended and causing issues such as crashing other parts of the script. Could someone please advise on what I might be doing wrong?

//scrolling----------------
//scrolling----------------
//scrolling----------------
var nav = $("#nav_id");
var nav_overflow = $("#nav_overflow");
var page_end_logo_nav = $("#page_end_logo_nav").visible();
var logo_container = $("#logo_container");
var nav_ani_speed = 200 //in ms
var nav_state = 0 // 0 is nav  1 is hamburger visible
var hamburger = $("#hamburgermenu") //hamburger element
var distanceY;
var shrinkOn;
var winkel_mand = $("#winkel_mand")

//set scroll for desktop nav
function nav_desktop_check() {
    distanceY = window.pageYOffset || document.documentElement.scrollTop;
    shrinkOn = 100;

    //run the header script
    if (distanceY > shrinkOn) {
        if (nav_state === 0) {
            nav_hamburger();
        }
    } else {
        if (nav_state === 1 ){
            if ($(window).width() >= 900){
                nav_normal_desktop();
            }
        }
    }
}

//tablet nav check
function tablet_nav_check() {
    if (nav_state === 0){
        if ($(window).width() <= 900){
        nav_hamburger();
        }
    }
}
tablet_nav_check()

//hambutton onclick
hamburger.click(function() {
    if (nav_state === 1){
        if ($(window).width() >= 900){
        nav_normal_desktop();
        } else {
            nav_normal_mobile();
        }

        logo_animation();
        remove_winkel_icon_check()
    } else{
        nav_hamburger()
    }


});

//nav to hamburger
function nav_hamburger() {
    hamburger.removeClass("active")
        nav_overflow.animate({
        width: 0
      }, nav_ani_speed, function() {
            hamburger.addClass("active")
      });
    nav_state = 1;
    logo_animation();
}

//hamburger to nav
function nav_normal_desktop() {
    hamburger.addClass("active");
    hamburger.removeClass("active");
    nav_overflow.css("width", "auto");
    nav_witdh = nav_overflow.innerWidth();
    nav_overflow.css("width", 0);
    nav_overflow.animate({
        width: nav_witdh
    }, nav_ani_speed, function() {
        hamburger.removeClass("active")
    });
    nav_state = 0;

}
function nav_normal_mobile() {
    nav_overflow.animate({
        width: "100%"
    }, nav_ani_speed, function() {
        hamburger.removeClass("active")
    });
    nav_state = 0;
}

Answer №1

Initially, I would ensure that all statements have semicolons where appropriate to avoid any potential errors.

Here is a brief example demonstrating overlay mask:

JavaScript

$('#element').on("click",function() {
  if($('#overlay').length == 0) {
        $(this).wrap('<div id="overlay"><div>');
  } else {
    $(this).unwrap();
  }

});

CSS

#element {
  width:200px;
  height:200px;
  background-color:#f00;
}

#inner {
  width:100px;
  height:100px;
  background-color:#0ff;
}

#overlay
{
  background-color:#000;
  opacity:0.3;
  width:200px;
  height:200px;
}

http://jsfiddle.net/5aw0wsy4/

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

Photo collection showcasing images in separate lines, created with a single div element per row

Currently, I am studying Scss and experimenting with creating an Image gallery using SASS. I am attempting to utilize only one div tag for the entire image gallery as a row, avoiding the need for a new div for each row. Would it be feasible to achieve th ...

An error occurred due to an unexpected token at the position of `>` of a `<>

I'm in the process of learning how to create a Tic-Tac-Toe game using React by following the tutorial found here. However, I encountered a syntax error when trying to run npm start, specifically around the use of <>. Steps to Recreate the Error ...

Position fixed causing website header to hide behind content

As I work on creating a website for a school, I aim to have a fixed header similar to what can be seen on Facebook. Despite trying out some fixes mentioned in this Stack Overflow [question][1], I am struggling to make it work effectively in my design. The ...

Enhancing WordPress Icons for Parent and Child Elements

I am seeking to customize icons on a WordPress website. The site contains a variety of product categories, including subcategories. https://i.sstatic.net/sTm1O.png My goal is to display one icon for parent categories and a different icon for child catego ...

Exploring the elements within array structures

I'm facing an issue with my API response. I'm trying to filter the links and check if the source and target name properties in each object match a specific string. However, I am having trouble accessing the name property. Any suggestions on how I ...

Javascript addClass and removeClass functions are not functioning as expected

Can you help me figure out why the icon still goes into the "startSharing" section even when it is turned off? In my html file, I have the following code for the icon: <div class="startSharing"></div> And in my javascript file, I have the fo ...

Discovering the indices of undefined array elements in JavaScript without using a loop

Is there a way in JavaScript to retrieve the indexes of undefined array elements without using a loop? Possibly utilizing a combination of map, filter, and indexOf? I have a loop solution that I'm seeking an alternative for - something more concise, ...

Issues with navigation menu not showing dropdown options and impacting webpage layout (HTML/CSS)

I'm having trouble creating a drop-down navigation menu using HTML and CSS. When I add the drop-down list, my menu extends onto two lines instead of one, and the drop-down menu doesn't appear when hovering. Here is a link to the jsfiddle for refe ...

What is the best way to showcase my subscription form on a web browser?

I am encountering an issue with my code. My goal is to generate a subscribe form modal. Although I have incorporated the subscribe form in my HTML document, upon running the code in the browser, the subscribe section is not visible. Can anyone offer assist ...

Activating development mode for LessCSS in Node.js

I'm encountering some major difficulties identifying LESS parse errors within a large CSS compilation. The error messages aren't providing much help (at least not for me). Here are my questions: 1. Is there a method to activate more debugging ...

Is there a way to transform a fixed parameter into a user input value and display the function's outcome on a different page?

I am in the process of developing a straightforward web application for book searching based on ISBN. The website will feature a text input field for entering an ISBN and a submit button. Essentially, a user can enter an ISBN in the designated box, click s ...

Add information to a table with JQuery

Is it possible to dynamically add JSON data to a table? The JSON data is in the format {"FirstName":"Cho" ,"LastName":"Chee","Company":"solution"}. Despite implementing the code, the data does not show up in the table as expected. Here is the jQuery Code: ...

JavaScript image sorting function fails to sort multiple ID elements that match

Currently, I am working on a project to develop an image sorter using toggle buttons. However, I have encountered an issue where my function is only effective for the first image ID and not any others. Below is the JavaScript function in question: functi ...

Is there a way to extract JSON information from the source code of an HTML page?

I'm currently in the process of extracting data from an online music database. Specifically, I am interested in retrieving information that can be identified using CTRL+F -- "isrc":"GB-FFM-19-0853." view-source: Utilizing Python and Selenium, I have ...

How can I design a versatile button in HTML/CSS3/jQuery/Javascript that utilizes images for borders and corners for maximum scalability?

Is there a way to create a completely scalable button in HTML/CSS3/jQuery+Plugins using images for borders and corners? I have attempted a messy method, but I am confident that there are more effective solutions available. The approach I considered invol ...

Vue js has a feature that enables users to input numbers with precision up to two decimal places

Currently facing an issue where I need to restrict input to no more than 2 decimal places. I came across a solution in a thread on Stack Overflow which addresses this using jQuery: JQuery allow only two numbers after decimal point. However, I am looking ...

Achieve consistent heights for divs within table cells without the use of JavaScript

Is it possible to make two divs contained in table cells in a shared row both have the height of the taller div without using JavaScript? Take a look at this simplified example here: http://jsfiddle.net/Lem53dn7/1/ Check out the code snippet from the fidd ...

Exploring the firestore section with vuefire for seamless access to methods

I am attempting to access a method in the firestore section of vuefire, but encountering the following error: vue-router.esm.js?8c4f:2257 TypeError: Cannot read property 'messagesWith' of undefined at eval (Chat.vue?62f3:214) This is the lin ...

Having difficulty organizing JavaScript Chart.JS charts into two rows, instead of having everything piled up in a single column

As I delve into JavaScript and Chart.JS for data visualization, I encountered a challenge with the layout. Despite resizing the charts in my template (linked below), all the charts are still displaying in a single column format. My goal is to have two rows ...

Issue with :visited pseudo-class not functioning as intended

My code includes all four basic pseudo-classes, and they all seem to be working fine except for the :visited pseudo-class. The color property doesn't function properly, and the background property appears to be inactive. I'm not sure what the iss ...