Javascript 响应请求上的非活动jquery

Javascript 响应请求上的非活动jquery,javascript,jquery,css,responsive,Javascript,Jquery,Css,Responsive,我的js中有这个脚本,我在滚动时更改了导航颜色,导航变成了白色。当我想停用脚本时,我会尝试响应 $(document).ready(function(){ var scroll_start = 0; var startchange = $('.change-col-nav'); var offset = startchange.offset(); if (startchange.length){ $(document).scroll(function() {

我的js中有这个脚本,我在滚动时更改了导航颜色,导航变成了白色。当我想停用脚本时,我会尝试响应

$(document).ready(function(){       
var scroll_start = 0;
var startchange = $('.change-col-nav');
var offset = startchange.offset();
    if (startchange.length){
        $(document).scroll(function() { 
        scroll_start = $(this).scrollTop();
        if(scroll_start > offset.top)   {
            $(".navbar-inverse").css({
                        "background-color": "#fff", 
                        "border-bottom": "1px solid #febe10",
                        "transition": "all 0.4s cubic-bezier(0.000, 0.000, 0.580, 1.000)"


                    });
                }

               else

               {
                  $('.navbar-inverse').css({
                      'background-color': 'transparent',
                      "border-bottom": "0",
                    });
               }

           });
            }
        });

当最小宽度768最大宽度991时,我希望此脚本处于非活动状态,我将如何执行该操作

将其包裹在if中,如下所示:

$(document).ready(function(){  

    // ... more code here

    $(document).scroll(function() { 

        if ($(window).width() > 768 && $(window).width < 991) {
            return;
        }

        // .... rest of your normal code here
    })
})
$(文档).ready(函数(){
//…这里有更多代码
$(文档)。滚动(函数(){
if($(window.width()>768&&$(window.width<991){
返回;
}
//……这里是您的正常代码的其余部分
})
})
函数myFunction(){
var scroll_start=0;
var startchange=$('.change col nav');
var offset=startchange.offset();
if(起始更改长度){
$(文档)。滚动(函数(){
scroll_start=$(this.scrollTop();
如果(滚动开始>偏移量顶部){
$(“.navbar inverse”).css({
“背景色”:“#fff”,“边框底部”:“1px实心#febe10”,“过渡”:“所有0.4s立方贝塞尔(0.000,0.000,0.580,1.000)”
}
);
}
否则{
$('.navbar-inverse').css({
“背景色”:“透明”,“边框底部”:“0”,
}
);
}
}
);
}
}
$(文档).ready(函数(){
var windowWidth=$(window.width();
如果(窗宽<768 | |窗宽>991){
myFunction();
}
});
$(窗口)。调整大小(函数(){
var windowWidth=$(window.width();
如果(窗宽<768 | |窗宽>991){
myFunction();
}
});
解决方案可以是

$(文档).ready(函数(){
var scroll_start=0;
var startchange=$('.change col nav');
var offset=startchange.offset();
if(起始更改长度){
$(文档)。滚动(函数(){
//如果在要求的宽度内,则阻塞
如果(window.innerWidth>=768&&window.innerWidth offset.top){
$(“.navbar反向”).css({
“背景色”:“fff”,
“边框底部”:“1px实心#febe10”,
“过渡”:“所有0.4s立方贝塞尔(0.000,0.000,0.580,1.000)”
});
}
其他的
{
$('.navbar反转').css({
“背景色”:“透明”,
“边框底部”:“0”,
});
}
});
}
});

我会使用媒体查询,而不会使用JavaScript检查宽度

$(窗口)。在(“滚动”)上,函数(){
var偏移=100;
$(document.body).toggleClass(“已滚动的活动”,$(窗口).scrollTop()>offset);
});
正文{
填充顶部:50px;
}
.滚动{
}
p{
边缘底部:50px;
}
#福{
位置:固定;
排名:0;
左:0;
背景色:#CCC;
宽度:100%;
}
介质(最小宽度:768px)和(最大宽度:992px){
.滚动激活#foo{
背景色:#FCC;
}
}

试验
我喜欢奶酪

我喜欢奶酪

我喜欢奶酪

我喜欢奶酪

我喜欢奶酪

我喜欢奶酪

我喜欢奶酪

我喜欢奶酪

我喜欢奶酪


我喜欢奶酪

该死。我的答案已经晚了15秒:)应该在卷轴上或者像Sumesh的答案那样调整大小。如果没有,请中断响应。如果可以使用
,为什么要使用
?你只有一行吗?@MihaiT,因为他正在激活它,而不是阻塞。这就是他使用
|
的原因,或者您可以使用CSS媒体规则在Scroll上添加和删除类,而不是在JavaScript代码中应用样式。
function myFunction() {
  var scroll_start=0;
  var startchange=$('.change-col-nav');
  var offset=startchange.offset();
  if (startchange.length) {
    $(document).scroll(function() {
      scroll_start=$(this).scrollTop();
      if(scroll_start > offset.top) {
        $(".navbar-inverse").css( {
          "background-color": "#fff", "border-bottom": "1px solid #febe10", "transition": "all 0.4s cubic-bezier(0.000, 0.000, 0.580, 1.000)"
        }
        );
      }
      else {
        $('.navbar-inverse').css( {
          'background-color': 'transparent', "border-bottom": "0",
        }
        );
      }
    }
    );
  }
}

$(document).ready(function() {
  var windowWidth=$(window).width();
  if(windowWidth < 768 || windowWidth > 991) {
    myFunction();
  }
});

 $(window).resize(function() {
  var windowWidth=$(window).width();
  if(windowWidth < 768 || windowWidth > 991) {
    myFunction();
  }
});
$(document).ready(function(){       
var scroll_start = 0;
var startchange = $('.change-col-nav');
var offset = startchange.offset();
    if (startchange.length){
        $(document).scroll(function() { 


            // BLOCK IF IN REQUESTED WIDTH
            if(window.innerWidth >= 768 && window.innerWidth <= 991) {
                return;
            }


        scroll_start = $(this).scrollTop();
        if(scroll_start > offset.top)   {
            $(".navbar-inverse").css({
                        "background-color": "#fff", 
                        "border-bottom": "1px solid #febe10",
                        "transition": "all 0.4s cubic-bezier(0.000, 0.000, 0.580, 1.000)"


                    });
                }

               else

               {
                  $('.navbar-inverse').css({
                      'background-color': 'transparent',
                      "border-bottom": "0",
                    });
               }

           });
            }
        });