Tips for stopping body scrolling when using a push-side menu

I am working on integrating a push-side menu plugin called Responsive Menu into a WordPress theme. Following the answer from SO @Congrim, I have successfully implemented a method to lock the body at scroll when the push-menu is open, with all elements including the header fixed, except for the interactive links with class="edge-ils edge-ils-with-scroll edge-ils-light" which will still move up when the push-menu is opened.

I have saved this functionality in a file named congrim.js and have enqueued the script in the theme's functions.php file:

function lockScroll() {
    if ($('body').hasClass('lock-scroll')) {
        $('body').removeClass('lock-scroll');
    }
    else {
        $('body').addClass('lock-scroll');
    }
}

$(document).ready(function() {
    $('#responsive-menu-pro-button').click(function() {
       lockScroll();
    }); 
});

Removing the jQuery wrap does not result in any errors in the browser console (tested in Chrome), but may not be the best practice when working with WordPress. Unfortunately, using overflow: hidden in the CSS class .lock-scroll does not work as expected when the push-side menu is open. It only allows me to use position: fixed instead of overflow: hidden.

The question:
Is there a way to prevent the interactive links with class="edge-ils edge-ils-with-scroll edge-ils-light" from moving up when the push-side menu is open, and keep them in their original position before the menu was opened?

Please focus on resolving the issue with the interactive links only, as the header, logo, and background pictures are displaying correctly.

Note: Using overflow: hidden seems to cause an unwanted shifting effect on the body during the show/hide scrollbar action, which is not occurring currently.

Update: The congrim.js file has been replaced with body-lock.min.js by Outsource WordPress. You can view the solution below.

Test the website page here.

Answer №1

Please review the provided solution below.

Step 1: Insert this CSS snippet:

.scroll-lock{position:fixed !important;}
.

Step 2: Include this JavaScript code.

$(document).ready(function() {
    var windowTop = 0;
    var menuOpen = 0;
    var offsetContainerList = 0;

    $('#responsive-menu-pro-button').click(function() {
        var offsetScrollList = $('.edge-ils-item-link:first').offset().top; 

        if ($('html').hasClass('scroll-lock')) {
            $('#responsive-menu-pro-container').one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",
              function(event) {
                  if (menuOpen==0) {
                      menuOpen = 1;
                      $('html').removeClass('scroll-lock');  
                      $('.edge-ils-content-table').css('top', eval(offsetContainerList)-40+'px'); //modify image container top position
                      $('html').scrollTop(windowTop); //scroll to initial position
                  }
                  else {   
                      menuOpen = 0;             
                  }
            });
        }
        else {                
            windowTop = $(window).scrollTop();
            offsetContainerList = $('.edge-ils-content-table').offset().top;  
            $('html').addClass('scroll-lock');      
            $('.edge-ils-content-table').css('top', -offsetScrollList + 'px'); //modify image container top position
        }      
    }); 
}); 

That's all!

Answer №2

Make sure to include the following code snippet in your custom JavaScript file:

 jQuery('#responsive-menu-pro-button').click(function(){
    var menu_active = jQuery(this).hasClass('is-active');
    if(menu_active){
        jQuery('body').css('position','fixed');
    }else{
       jQuery('body').css('position','static');
    }
});

I hope this information proves useful for you.

Thank you

Answer №3

It seems like your scrolling behavior is not standard and is being controlled by a JavaScript function that manipulates classes to mimic a scroll effect (edge-appeared, edge-up, edge-down).

Even if the menu opens, these classes are reset, and adding overflow-hidden won't change this behavior.

You'll need to identify the specific JavaScript code responsible for manipulating those classes and stop it from doing so. I'd be happy to assist further, but given the number of JS files present, it will take some time to analyze them all. If you can provide a Minimal, Complete, and Verifiable example, it would greatly help in troubleshooting the issue.

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

Adjusting text to fit alongside an undefined image's width

Let's keep this straightforward. I've got an image that uses the following CSS properties: .img-right { float: right; margin: 0px 0px 10px 20px; } Below the image, there's a caption with these CSS styles: .img-right p { margin-top: 5px; ...

Customizing the Navigation Border-Bottom in WordPress

Currently, I am working on a project with this website. My main focus is on removing the border-bottom in the navigation bar for the last two right navigation points which are "DE" and "FR". Despite trying various CSS solutions, such as: #menu-item-394 { ...

Comparison between bo-html and bo-text

As I was going through the documentation for the bindonce directive, a question popped into my head regarding the distinction between bo-html and bo-text. bo-html: This evaluates "markup" and displays it as HTML within the element. bo-text: ...

Trouble navigating from plugin to theme folder: reference behaving unexpectedly

In a specific wordpress theme, the javascript and jquery files can be found at /functions/extended/js/ Originally, they were located in a plugin folder. I now need to change the references to a folder within the theme. This was my original code: if ( is ...

Allow specific HTML tags to be unescaped in Vue.js

Utilizing the v-html method to unescape HTML tags, I am seeking a way to only unescape the <a></a> tags within a string. To illustrate this: Input: <p> Hello World </p> <a target="_blank" href="https://www.google. ...

Having trouble accessing the selected item in the $scope when using ng-options inside ng-repeat?

I am looking to achieve the following: I have an array called 'all' that contains all possible items. I want to create a subset of that array and store it in 'subset': JavaScript (js.js): var app = angular.module('myApp', [ ...

The year slider on d3 showcases the specific regions between each incremental step

I am working on creating a step slider in d3 (v5) that spans from the years 2000 to 2021 using the d3-simple-slider plugin. const slider = sliderBottom() .min(new Date(2000, 1, 1)) .max(new Date(2020, 1, 1)) .tickFormat(d3.timeFormat(& ...

Is there a way to execute server-side functions with HtmlService?

I am currently learning programming and I'm experimenting with setting up buttons using jQuery in Google Apps Script. I have a spreadsheet with a menu that opens a dialog box created with HtmlService. Inside the dialog box, there are two buttons - o ...

Ways to design each element in React

I'm currently working on a React code that involves CSS for Scrolling functionality. When I try to use props.children.map, I encounter an error saying "TypeError: props.children.map is not a function". Since I am in the process of learning React.js, t ...

Error in test runner: Cannot convert type 'Cucumber' to type '? extends Runner' in Java cucumber

I'm currently working on setting up the Cucumber framework using Java for running my tests, but encountering a type mismatch error in the Test Runner. package cucumbertest; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import ...

A guide on converting JSON strings into arrays using Javascript

In my JavaScript program, I have a Mocha test that checks if all available currencies are displayed in a drop-down list: it('displays all available currencies in drop down list', () => { return invoiceEditPage.details.currencyDropDown.dr ...

.delete is functional on Chrome and Safari, but ineffective on Firefox and Internet Explorer

Recently, I came across a jQuery script that enables the creation of a table with a button to add rows at the bottom. Each row also contains links for deleting specific rows. While this functionality works seamlessly in Chrome and Safari, it seems to encou ...

When the screen is minimized, my website doesn't align to the center as expected

When the screen is maximized everything looks great, but when I minimize it, the content doesn't center. I tried using margin: auto; in the "main-div" class, but then everything shifted to the top left corner. So, I added a "wrapper-div" to contain th ...

My attempts to submit a form to a new tab and redirect the current window are failing in Chrome and Safari

I'm attempting to accomplish two tasks simultaneously: (1) submit a form to an external website that opens in a new tab and (2) direct the browser window containing the form to a thank you page. Currently, my code functions correctly in Firefox and I ...

Is there a way to implement a method on AirDatepicker within my custom JavaScript file?

I am currently working with AirDatepicker v3.3.5 in my app.js file: window.dateRangePicker = new AirDatepicker('.date-range', { range: true, maxDate: new Date(), multipleDatesSeparator: ' - ' }); After referring to the docu ...

Transform the JSON response into a map

I have a functioning code that I am looking to adjust. let table_specs = {'columns': [ {'name': 'Col1', 'width': 7, ....}, {'name': 'Col2', 'width': 8, . ...

The $ symbol is not recognized in this context [jQuery, MasterPage, UserControl, Shared/static Event handler, external javascript]

Unfortunately, I am facing a challenge in replicating this issue outside of my application. If anyone is willing to assist, I have a VS2012 project that can be shared for further investigation. The functionality works fine in isolation but fails in a large ...

Node.js and the Eternal Duo: Forever and Forever-Montior

Currently, I am utilizing forever-monitor to launch a basic HTTP Node Server. However, upon executing the JavaScript code that triggers the forever-monitor scripts, they do not run in the background. As a result, when I end the TTY session, the HTTP server ...

Exploring Nested XML: Displaying nested XML data dynamically on an HTML webpage

Request: Clients are able to supply any XML file (along with an XSD file that includes the schema of the XML file) containing data. I am required to display a 'data preview' on the asp.net core website and save the Schema of the XML in a hierarch ...

Implement a vertical scrolling animation in datatables

I am trying to utilize datatables to display all data. My goal is to have the data automatically scroll row by row every 3 seconds. This is my code, and you can also check it out on jsfiddle The intention is to showcase this data on a large screen. < ...