Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript JS Smooth Scroll Href Exception

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #166066
    Rahmanyinov
    Participant

    Hi! I need some help with a javascript function. Somewhere I’ve found this smooth scrolling code:

         $(function() {
              $('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 //-65 //fixed header height
                    }, 1000);
                    return false;
                  }/**/
                }
              });
            });

    It works fine, however I have on the same page(s) a dropdown nav, and it uses the anchor link (#nav) to show/hide the first level elements of nav on mobiles. With that javascript above, this show/hide function doesn’t work, so I need to exclude the #nav href in this JS code. How can I do that?

    Thanks!

    #166531
    Taufik Nurrohman
    Participant

    Make your selector to be more specific, example:

    $('.container a[href*=#]:not([href=#])')
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.