Search code examples
javascriptjquerygsapscrollmagic

Smooth scroll for specific anchor tags not for all anchor tags


I am trying to implement the smooth scroll when user click on the anchor tag then it will scroll and reach the target. it's working perfectly with all the anchor tag.

Now my issue is,

I have two tabs called as part1 and part2. There is no data in part1 but I have 3-4 anchor tags in the part2. I have to set a smooth scroll for that.

I don't want a smooth scroll when the user clicks on part1 or part2.

<div class="tabs">
            <ul class="tab_click">
                  <li class="current"><a href="#part1" >Part1</a></li>
                  <li><a href="#part2">part2</a></li>
            </ul>
      </div>

I need a smoth scroll when user click on the below anchor tag.

<ul>
          <li><a href="#about">About</a></li>
          <li><a href="#services">Services</a></li>
          <li><a href="#contact">Contact</a></li>
          <li><a href="terms.php">Terms</a></li>
        </ul>

Please check below link, I added my whole code here. https://codepen.io/Narendra_verma/pen/bjgXyK

Would you help me out in this issue


Solution

  • you can add main class for smooth scrolled link

    at line 30

        $(document).on("click", ".main_tab a[href^=#]", function(e) {