Issues with closing Foundation 6 off-canvas feature

Here is a link that I have:

If you click on the skip button in the middle, it will take you to the next slide where Foundation 6 off-canvas is implemented.

The header containing the toggle button for the off-canvas menu is located outside of the menu itself and appears like this:

        <header class="fixed close">
            <div class="hamburger" data-toggle="sth">
                <button type="button>
                    <span></span>
                    <span></span>
                    <span></span>
                </button>
                <span class="menu">Menu</span>
            </div>
            <div class="logo">
                <h1>Aldemar</h1>
                <span>productions</span>
            </div>
            <span class="mail-icon float-right" data-open="contact-us">
            </span>
        </header>

I have included the following JavaScript code to close the off-canvas menu:

$('.hamburger').on('click', function(e){
    e.preventDefault();
    if($('header').hasClass('close')){
        $('header').removeClass('close').addClass('open');
        $(this).find('button').toggleClass('open');
        $('body').addClass('block-view');
    }
    else {
        $('.off-canvas').foundation('close');
        $('header').removeClass('open').addClass('close');
        $(this).find("button").toggleClass('open');
        $('body').removeClass('block-view');
        $('#sth').foundation('close'); 
    }
});

However, there seems to be an issue with this part: $('#sth').foundation('close'); as it does not successfully close the menu.

Answer №1

After closing the menu and seeing the header slide back to the left, it seems that the div labeled as off-canvas-wrapper-inner is still holding onto the classes is-off-canvas-open and is-open-left. To fix this issue, consider removing these classes when executing

$('header').removeClass('open').addClass('close')
.

Another approach would be to follow the Foundation off-canvas guidelines found in the documentation (). By adhering to these standards, a custom event for toggling the menu may not be necessary.

Answer №2

After removing the "data-toggle="sth"" attribute, I made some adjustments to my JavaScript code:

$('.hamburger').on('click', function(e){
    e.preventDefault();
    if($('header').hasClass('close')){
        $('header').removeClass('close').addClass('open');
        $(this).find('button').toggleClass('open');
        $ ('body').addClass('block-view');
         $('#sth').foundation('open');
     }
     else {
            $('.off-canvas' ).foundation('close') ;
             $('he ader').removeCl ass('op en ').addClas s('clo se');
              $(this) .find('button ' ).toggle Class('op en' );
               $('bo dy'). removeC lass( '
                 bloc k-vie w ');
                  $('# sth').foundation('clos e'); 
                } 
});

I had to manually handle the menu opening and closing.

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

What is the best way to adjust and filter an array based on a single value?

Here is an array that needs to be modified: [ {name: "test", value: "test", group: 0}, {name: "test1", value: "test2", group: 0}, {name: "test3", value: "test3", group: 1}, {name: "te ...

What could be causing the issue of being unable to connect to the NodeJS express server from any network?

Imagine having a web server running on port 3001 with the IP address 23.512.531.56 (obviously not a real one) and then switching to another network, like your neighbor's. Now, when you try entering 23.512.531.56:3001 in Chrome, why doesn't the se ...

The value of Express session within the callback is not retained when accessed outside

I'm encountering an issue with my Express route setup. Here's the current code snippet: app.get("/route", function(req, res){ if (someBoolean){ someFunction(stuff, function(user){ ... req.session.user = user; ...

Having trouble with sending an AJAX request to a different domain?

I've been attempting to utilize the following API: However, upon making an AJAX call, I encounter this specific error: XMLHttpRequest cannot load /radius.json/30341/10/mile. No 'Access-Control-Allow-Origin' header is present on ...

When attempting to use the search bar to filter in ReactJs, an error occurs: TypeError - Unable to access properties of undefined (specifically 'filter')

When I receive data from my JSON server on the console, everything looks good. But when I try to type something in order to filter it, an unhandled error occurs with the message: 1 of 1 Unhandled Error Unhandled Runtime Error: TypeError: Cannot read prop ...

The Npm generate script is failing to create the necessary routes

I've integrated vue-router into my nuxt project, but I encountered an issue when running npm run generate - it generates everything except for my pages. I suspect the problem lies with the router implementation as I didn't face any issues before ...

Use a spy to mock a component method using karma and jasmine

Encountering this error message during testing: ERROR: 'Error during cleanup of component' The issue stems from the following code snippet : ngOnDestroy(){ methodCallToMock() } To address this, I need to mock the methodCallToMock() functi ...

Display a compilation either in the backend or the frontend

I'm fairly new to NodeJS and I could really use some advice. I currently have a webpage that displays a list of users, which is retrieved from a collection using Mongoose. I am aware of two different ways to display this list: 1) One option is to que ...

The div functions seem to stop working properly after they have been multiplied

Initially, I use JavaScript to multiply the div but then encounter issues with the function not working properly. function setDoorCount(count) { $('.doors').html(''); for (var i = 0; i < count; i++) { var content = " ...

Button press triggers the fadeIn function successfully, but the keypress event does not have the same effect

I'm currently facing an issue with two div elements on my webpage. I want only one of them to be visible at a time, depending on which key is pressed. If the 1 key is pressed, I want 'div1' to fadeIn (if it's not already visible) and fo ...

Angular tutorial: Organizing data by date only

This is my first time building an Angular app. I am fetching JSON data from an API using a factory service to get football match fixtures. My goal is to group these fixtures by date while disregarding the time component. The date string in the JSON is fo ...

What are the steps to correctly implement async await in a standard sequence?

When I press the button onPress={() => Login()} First, I need to obtain a token by using the signInWithKakao function. Secondly, right after acquiring the token, if it is available, I want to dispatch the profile using the kakaoprofile function. Howev ...

Using jQuery to decrease the size of a div element containing an image

Hello everyone! I have an image inside a div and I am currently moving it down at a specific time using a delay. My question is, how can I make the image shrink as it moves down the screen until it eventually disappears completely at a set location? Curre ...

Guide on invoking a function in a PHP file using jQuery's load method

I am having trouble displaying the data retrieved from the database. There is a function called "getComments(page)" in the getComments.php file, where 'page' is an integer parameter corresponding to the chosen database. I need to call this functi ...

Submit a form to the same page without reloading and toggle the visibility of a div after submission

Is there a way to submit a form without refreshing the page and hiding the current div while showing a hidden one? I attempted to use the following code, but it ends up submitting the form and reloading the page. <form method="post" name="searchfrm" a ...

React page is not loading properly after refreshing, displaying unprocessed data instead

Hello everyone! I am currently working on developing an app using Node, React, and Mongoose without utilizing the CRA command, and I have also incorporated custom webpack setup. Initially, I was able to build everything within a single React page (App.jsx ...

Insufficient module names remaining in NPM

Starting to release modules on NPM has been on my mind, but I can't help but worry about the limited availability of sensible module names in the public domain. Is there a way to create a public NPM module that organizes all my module names within a ...

Tips for transferring localstorage values from the view to the controller in order to utilize them as a PHP variable in a separate view

How can I pass the value from local storage as a PHP variable when using location.href in the controller after clicking a button? In the view: echo Html::button('Proceed', [ 'onclick' => " var dataVal = localStorage.g ...

Using the drag and drop feature with the v-textarea component in Vuetify

Struggling to incorporate a Drag and Drop feature on vuetify v-textarea. Encountering an issue where clicking on the v-textarea results in the value from a dropped component being removed. Unsure if it's a flaw in my code or a limitation in vuetify v- ...

How can you utilize the Array submission syntax within HTML coding?

I currently have numerous input fields within a form, and some of them are structured like this: <input name="agents[]" type="file" /> Additionally, imagine there is a plus button next to this field as shown below: <img src="plus.jpg" id="some_ ...