Conflict Bootstrap4 Nav pills with Smoothscroll

I need Smoothscroll for some buttons but NOT for the NAV PILLS.

I can´t use Scrollspy cause it must be used on a Bootstrap nav component or list group.

-Smoothscroll-

$(document).ready(function(){
   // Add smooth scrolling to all links
   $("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
       $('html, body').animate({
         scrollTop: $(hash).offset().top
       }, 800, function(){

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

NAV PILL CODE

<ul class="nav nav-pills nav-fill mb-5" id="pills-tab" role="tablist">
              <li class="nav-item" role="presentation">
                <a class="nav-link active pilltxt" id="pills-v2-tab" data-toggle="pill" href="#tab-v2" role="tab" aria-controls="tab-v2" aria-selected="true">V2</a>
              </li>
              <li class="nav-item" role="presentation">
                <a class="nav-link pilltxt" id="pills-profile-tab" data-toggle="pill" href="#tab-v" role="tab" aria-controls="tab-v" aria-selected="false">VX</a>
              </li>
              <li class="nav-item" role="presentation">
                <a class="nav-link pilltxt" id="pills-contact-tab" data-toggle="pill" href="#tab-v0" role="tab" aria-controls="tab-v0" aria-selected="false">V0</a>
              </li>
              <li class="nav-item" role="presentation">
                <a class="nav-link pilltxt" id="pills-contact-tab" data-toggle="pill" href="#tab-m" role="tab" aria-controls="tab-m" aria-selected="false">MN</a>
              </li>
            </ul>

BUTTON CODE

 <div class="col-12 col-xl-6 ml-0 pl-0">
                              <a class="btn btn-manchester shadow d-none d-md-block btn-conocelas" href="#conocelas" role="button" style="left: 0; text-decoration: none">¡Conocelas! ></a>
                              </div>

Thank you fot your help.



Read more here: https://stackoverflow.com/questions/65728107/conflict-bootstrap4-nav-pills-with-smoothscroll

Content Attribution

This content was originally published by Emmanuel Grooviedelik at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: