Javascript 在滚动和最大宽度上启动脚本

Javascript 在滚动和最大宽度上启动脚本,javascript,html,css,responsive-design,scroll,Javascript,Html,Css,Responsive Design,Scroll,我有这个: JavaScript: $(window).scroll(function(){ if ($(window).scrollTop() >= 100){ $('#normal_menu').css({height: '50px'}); } else { $('#normal_menu').css({height: '120px'}); } }); 很好用。但是现在我只希望代码在屏幕宽度小于924px时工作。我发现:if($(window).wi

我有这个:

JavaScript:

$(window).scroll(function(){
if  ($(window).scrollTop() >= 100){
     $('#normal_menu').css({height: '50px'});
} else {
     $('#normal_menu').css({height: '120px'});
    }
});  
很好用。但是现在我只希望代码在屏幕宽度小于924px时工作。我发现:
if($(window).width()<924)
但如何在我的代码中实现这一点呢?

试试这个:

$(window).scroll(function () {
    if($(window).width() < 924) { // <--- inserted if statement here.
    if ($(window).scrollTop() >= 100) {
        $('#normal_menu').css({
            height: '50px'
        });
    } else {
        $('#normal_menu').css({
            height: '120px'
        });
    }
    } // <--- inserted closing bracket here.
});
$(窗口)。滚动(函数(){
if($(window.width()<924){/=100){
$(“#正常菜单”).css({
高度:'50px'
});
}否则{
$(“#正常菜单”).css({
高度:'120px'
});
}

}//在交互过程中调整窗口大小是否有问题?(并且经常需要检查窗口的宽度)是的,我会在可以的时候(必须等待10分钟)。还有一个问题:如果我想让效果平滑,怎么办?您可能想使用
animate()
…检查我找到的这个。