jquery用于if语句,就像CSS媒体查询一样

egr*_*103 0 jquery if-statement browser-width media-queries

我有这个jquery代码很好用:

$(document).scroll(function(){
    if ($(this).scrollTop()>175){
        // animate fixed div to small size:
        $('header').stop().animate({ height: 90 },100);
    } else {
        //  animate fixed div to original size
        $('header').stop().animate({ height: 175 },100);
    }
});
Run Code Online (Sandbox Code Playgroud)

我需要以上所有浏览器/设备随时出现并阅读,但我还需要调整较小标题的高度(当前为90px - 在行下方//将固定div设置为小尺寸:)仅适用于浏览器宽度介于641px和959px之间.对于那些浏览器宽度,我需要标题的高度为120px,否则使用上面的代码.

有点像媒体查询,我希望它在浏览器调整大小时自动更新.

我该怎么做?

Tah*_*ksu 6

$(window).width();
Run Code Online (Sandbox Code Playgroud)

是你在找什么.和,

$(window).on("resize",function(){  
   if($(window).width()>641 && $(window).width()<959){
          // do the animations
   }    
}
Run Code Online (Sandbox Code Playgroud)

是它的主要思想.