Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.resize不在滚动时调整大小_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript window.resize不在滚动时调整大小

Javascript window.resize不在滚动时调整大小,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个jQuery代码,可以滑动/切换导航。之后,我使用window.resize重置HTML中的style属性,以便在调整浏览器窗口大小时显示导航。代码如下: $(window).resize(function(){ $("nav").removeAttr('style'); $(".level_2").removeAttr('style'); $(".menu-expander").removeClass('close'); }); 现在我遇到了一个问题,当我在智

我有一个jQuery代码,可以滑动/切换导航。之后,我使用window.resize重置HTML中的style属性,以便在调整浏览器窗口大小时显示导航。代码如下:

$(window).resize(function(){
    $("nav").removeAttr('style');
    $(".level_2").removeAttr('style');
    $(".menu-expander").removeClass('close');
});
现在我遇到了一个问题,当我在智能手机上向下滚动或从纵向视图更改为横向视图时(例如,当我进行长距离导航时),导航显示关闭

是否有可能检查是否刚刚更改了视图或在页面上滚动,以便在调整Browser窗口的大小时,window.resize刚好出现


PS:这是代码笔上的代码:

我找到了一个解决方案:我为宽度设置了一个变量,并将其放入if:

$(window).resize(function(){
  var width = $(window).width();
  if(width > 700) {
    $("nav").removeAttr('style');
    $(".level_2").removeAttr('style');
    $(".menu-expander").removeClass('close');
  }
});

很难确切地理解您想要做什么,但听起来CSS媒体查询更适合您的目标。我使用slideToggle打开/关闭我的naivgation mobile。它为导航设置显示:块或显示:无。当我调整browserwindow的大小并且之前切换了导航时,导航的属性为display:none。所以我用resize函数重置了style属性。但现在我的问题是,当我在手机上滚动或从纵向视图切换到横向视图时,它也会出现。我正在寻找一种可能,在调整browserwindow的大小时重置style属性。您可以通过JSFIDLE或plunker发布它吗?是的,在这里: