jQuery ScrollTop多链接问题
这样做时,下面的代码可以正常工作jQuery ScrollTop多链接问题,jquery,jquery-animate,scrolltop,Jquery,Jquery Animate,Scrolltop,这样做时,下面的代码可以正常工作 $('#privacyPolicy').click(function(){ $('wrapper, div').animate({scrollTop:$('#privacyPolicy' + 'link').offset().top - 230}, 'slow'); }); 但我需要它与多个链接一起工作? 我试过这个: $('#content
$('#privacyPolicy').click(function(){
$('wrapper, div').animate({scrollTop:$('#privacyPolicy' + 'link').offset().top - 230}, 'slow');
});
但我需要它与多个链接一起工作?
我试过这个:
$('#contents a').click(function(){
$('wrapper, div').animate({scrollTop:$('id' + 'link').offset().top - 230}, 'slow');
});
我做错了什么?
提前感谢您在此提供的任何帮助。您需要使用
每个
$('#contents a').each(function(){
$(this).click(function(){
$('#wrapper, div').animate({scrollTop:$('id' + 'link').offset().top - 230}, 'slow');
});
});
尝试替换此行:
$('wrapper, div').animate({
scrollTop:$(this.id + 'link').offset().top - 230
}, 'slow');
注:
刚刚看到这个$('wrapper
应该在前面加上id符号
或类符号
我刚刚发现我做错了什么,我需要更改“#”+$(this).attr('id'))。非常感谢!我建议您现在接受Rab的回答,并在此处添加适当的注释,因为Rab建议为“wrapper”添加#前缀