从 jquery 滚动函数中排除具有特定父级的 "a" 标签

Exclude "a" tags with specific parent from jquery scroll function

我使用下面提供的脚本在我的页面上实现了平滑滚动。 但我还实现了一个选项卡部分。而且我不希望在那里实现平滑滚动。

这是我的 jquery 代码:

$('a[href*="#"]')
    // Remove links that don't actually link to anything
    .not('[href="#"]')
    .not('[href="#0"]')
    .click(function(event) {
      // On-page links
      if (
        location.pathname.replace(/^\//, "") ==
          this.pathname.replace(/^\//, "") &&
        location.hostname == this.hostname
      ) {
        // Figure out element to scroll to
        var target = $(this.hash);
        target = target.length
          ? target
          : $("[name=" + this.hash.slice(1) + "]");
        // Does a scroll target exist?
        if (target.length) {
          // Only prevent default if animation is actually gonna happen
          event.preventDefault();
          $("html, body").animate(
            {
              scrollTop: target.offset().top - 91
            },
            1000,
            function() {
              // Callback after animation
              // Must change focus!
              var $target = $(target);
              $target.focus();
              if ($target.is(":focus")) {
                // Checking if the target was focused
                return false;
              } else {
                $target.attr("tabindex", "-1"); // Adding tabindex for elements not focusable
                $target.focus(); // Set focus again
              }
            }
          );
        }
      }
    });

我想排除所有作为服务菜单区域 class 子项的 a 元素。

我会提供 html:

<div class="service-menu-area">
  <ul class="nav">
      <li>
        <a class="active" data-toggle="tab" href="#spa">
              <span class="service-icon">
                  <img src="img/icon/service-icon1.png" alt="">
              </span>
         <span class="service-title">Room Service</span>
         <span class="text">
         <span>Room Service</span> 
         luptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia 
         </span>
         </a>
     </li>
</ul>
</div>

所以我希望当我单击其中一个 html 选项卡时,我不会看到任何滚动动画。

您可以在添加 .click 处理程序之前添加 .not('.service-menu-area a')