Skip to content

Off-canvas menu closing after click to a link #8

Description

@dragosct

If in the off-canvas menu exists a tags that are targeting an element from the same page and you click on them, the off-canvas menu will remain open after click. In the following lines of code I will put a way that will make off-canvas to close after click.

  1. In the html page you have to insert the following attributes on a tags: data-scroll="true" and data-id="#something" like this: <a href="" data-scroll="true" data-id="#something"></a> for properly working javascript functions from the step 2. Then you must put an id="something" attribute on you're targeted element for example <div id="something"></div>.

  2. You need to go in assets/js/ct-paper.js on line 100 and put the following code:

$('a[data-scroll="true"]').click(function(e){
        var scroll_target = $(this).data('id');
        var scroll_trigger = $(this).data('scroll');

        if(scroll_trigger == true && scroll_target !== undefined){
            e.preventDefault();

            $('html, body').animate({
                 scrollTop: $(scroll_target).offset().top - 50
            }, 1000);
        }
 });

 $('.navbar-collapse a[data-scroll="true"]').click(function(){
        setTimeout(function(){
            if(gsdk.misc.navbar_menu_visible == 1) {
                $('html').removeClass('nav-open');
                gsdk.misc.navbar_menu_visible = 0;
                $('#bodyClick').remove();
                 setTimeout(function(){
                    $toggle.removeClass('toggled');
                 }, 550);
            }
        }, 550);
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions