Problem with Side Menu

0

I'm correcting the page of the company where I work and has some problems, I put a side menu as requested by the boss but I have the problem that when you go to another section and click on the menu you go back home

This is my menu button code:

<a id="menu-toggle" href="#" class="glyphicon btn-menu toggle">
                                        <i class="fa fa-bars fa-2x"></i>
                                    </a>

and here what goes on the side part

<div id="wrapper">

    <!-- Sidebar -->
        <div id="sidebar-wrapper">
            <nav id="spy">
                <ul class="sidebar-nav nav">
                    <li class="sidebar-brand">
                        <a href="index.php" style="color:#de3053; font-size: 20px;">
                        <strong>
                            BOOSTERWISE
                        </strong>
                    </a>
                    </li>
</ul>
</nav>
</div>
<div id="page-content-wrapper">
contenido de página
</div>
</div>

here the Script

<script type="text/javascript">

/*Menu-toggle*/
$("#menu-toggle").click(function(e) {
    e.preventDefault();
    $("#wrapper").toggleClass("active");
});

/*Scroll Spy*/
$('body').scrollspy({ target: '#spy', offset:80});

/*Smooth link animation*/
$('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') || location.hostname == this.hostname) {

        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
        if (target.length) {
            $('html,body').animate({
                scrollTop: target.offset().top
            }, 1000);
            return false;
        }
    }
});
</script>

I just need you not to go home ...

The page I'm working on

    
asked by Oscar Eduardo Crespo Couoh 03.11.2016 в 19:03
source

1 answer

0

On this page (unfortunately this is in English) solve the same problem that you have, replace your code js

$(document).ready(function() {
    function filterPath(string) {
        return string
            .replace(/^\//, '')
            .replace(/(index|default).[a-zA-Z]{3,4}$/, '')
            .replace(/\/$/, '');
    }
    $('a[href*=#]').each(function() {
        if (filterPath(location.pathname) == filterPath(this.pathname) && location.hostname == this.hostname && this.hash.replace(/#/, '')) {
            var $targetId = $(this.hash),
                $targetAnchor = $('[name=' + this.hash.slice(1) + ']');
            var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
            if ($target) {
                var targetOffset = $target.offset().top;
                $(this).click(function() {
                    $('html, body').animate({ scrollTop: targetOffset }, 400);
                    return false;
                });
            }
        }
    });
});
  

JQuery is still hijacking links that have an inline onclick handler (but, oddly, only the first time those links are clicked). To fix this problem, we can replace the .click () with .each ()

Interesting link

    
answered by 03.11.2016 в 19:18