我有这段代码可以使标题和标题中的 img 在向下滚动时缩小。它工作正常,除了它真的很跳跃,因为一个 css 属性先于另一个改变。有没有办法同时进行这两项更改?
$(window).scroll(function() {
if ($(this).scrollTop() > 0){
$('#section-header-0').css({
'line-height' : '44px'
});
$('#logo').css({
'width' : '200px'
});
}
else{
$('#section-header-0').css({
'line-height' : '96px'
});
$('#logo').css({
'width' : '394px'
});
}
});
最佳答案
$(window).scroll(function() {
if ($(this).scrollTop() > 0){
$('#section-header-0').css({
'line-height' : '44px'
},{ duration: 200, queue: false });
$('#logo').css({
'width' : '200px'
},{ duration: 200, queue: false });
}
else{
$('#section-header-0').css({
'line-height' : '96px'
},{ duration: 200, queue: false });
$('#logo').css({
'width' : '394px'
},{ duration: 200, queue: false });
}
});
我希望上面的内容对你有帮助队列:false 基本上告诉他们立即运行而不是在队列中运行
关于javascript - 如何使用 jQuery 同时在多个元素上更改不同的 css 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29976871/