gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 20:09:16 25 4
gpt4 key购买 nike

我使用 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*="#"]')

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

当时引起了相当大的动荡,尤其是因为许多“专业”WordPress 主题都在使用它并在一夜之间崩溃。当人们意识到他们购买的产品无法实现他们认为的基本功能时,观察他们的 react 很有趣。

查看本期:https://github.com/jquery/jquery/issues/2824

关于javascript - 使用最新的 jQuery 的视差滚动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52568772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com