Bootstrap affix smooth scroll

671 views Asked by At

I have been working on bootstrap scrollspy (affix) and it worked fine. I added a script for a smooth movement whenever you click sections.

But it doesn't seem to be working properly.

  • When you click "section3", it's not move section3.
  • When you double click, it goes wrong section.
  • fix nav is not fixed and not showing on responsive.

This is an example page, with the following code:

$(document).ready(function() {
  // Add scrollspy to <body>. changed to half-right-wrap
  $('div.half-right-wrap').scrollspy({
    target: ".navbar",
    offset: 50
  });

  // Add smooth scrolling on all links inside the navbar
  $("#myNavbar a").on('click', function(event) {
    // Make sure this.hash has a value before overriding default behavior
    if (this.hash !== "") {
      // Prevent default anchor click behavior
      event.preventDefault();

      // Store hash
      var hash = this.hash;

      // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
      $('div.half-right-content').animate({
        scrollTop: $(hash).offset().top
      }, 600, function() {

        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
      });
    } // End if
  });
});

** Please have a look at PC size to see "affix nav"

How can we make it properly? I guess I added wrong selector in js. It was "body" and add my own selector.

0

There are 0 answers