最新 jQuery 的视差滚动不起作用

Parallax scroll with the newest jQuery isn't working

我使用了 jQuery 脚本来实现视差效果。该脚本适用于 jQuery 的旧版本(直到版本 1.11.3),但是当我用最新版本替换它时,平滑滚动效果不起作用。现在有人不再支持代码的哪一部分了吗?

$(document).ready(function() { 
  $('a[href*=#]').each(function() {  
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')   && location.hostname == this.hostname   && this.hash.replace(/#/, '')) {   
      var $targetId = $(this.hash),
        $targetAnchor = $('[name=' + this.hash.slice(1) + ']');   
      var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;    
      if ($target) {     
        var targetOffset = $target.offset().top;

             
        $(this).click(function() {
          $("#nav li a").removeClass("active");
          $(this).addClass("active");      
          $('html, body').animate({
            scrollTop: targetOffset
          }, 1000);      
          return false;     
        });   
      }  
    } 
  });
});

是选择器。

$('a[href*=#]') 替换为 $('a[href*="#"]')

从一开始就不是一个有效的选择器
当他们修复它时,所有使用有缺陷的(但直到那时)语法的脚本都崩溃了。

当时引起了相当大的动荡,尤其是因为很多 "pro" WordPress 主题都在使用它并在一夜之间崩溃。当人们意识到他们购买的产品在他们认为的基本功能上出现故障时,观察他们的反应很有趣。

看到这个问题:https://github.com/jquery/jquery/issues/2824