How to make menu work for external link

Asked

Viewed 290 times

2

I am using the following script to make a sliding effect between sections of my site (anchored links. P.E. #contact). However my menu has an external link, how do I make it work?

$(function() {

var navH = $('body > .nav').outerHeight(true);

$('body').css({
"margin-top": navH + "px"
});

$('body > nav .container-fluid .navbar-collapse .nav ').on("click", 'a', function(e) {
e.preventDefault();

var target = $(this).attr("href"),
  elementOffset = $(target).offset().top,
  distance = (elementOffset - navH);

$("html, body").stop(true, true).animate({
  scrollTop: distance
}, '500', 'swing', function() {
  $('body > .nav .active').removeClass("active");
  $('a[href="' + target + '"]').parent().addClass('active');
});
});
});

1 answer

1

Solved. Includes the "slide" class on the line:

$('body > nav .container-fluid .navbar-collapse .nav .desliza ').on("click", 'a', function(e) {

and in the tags < li > before the links.

<li class="desliza">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.