Javascript 当屏幕小于1000时停止jquery函数

Javascript 当屏幕小于1000时停止jquery函数,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我的jQuery脚本有问题。我正在尝试制作一个带有子菜单的响应菜单。仅当鼠标输入其父菜单时,子菜单才会下拉,但一旦我调整屏幕大小(小于1000),我需要停止此鼠标输入功能 我甚至尝试加入'j'变量,使其成为一个boleen。如果屏幕尺寸小于1000,“j”设置为1 var j = 0; jQuery(document).ready(function(){ if(j==0){ console.log('enter function running'); jQuery('ul[

我的jQuery脚本有问题。我正在尝试制作一个带有子菜单的响应菜单。仅当鼠标输入其父菜单时,子菜单才会下拉,但一旦我调整屏幕大小(小于1000),我需要停止此鼠标输入功能

我甚至尝试加入'j'变量,使其成为一个boleen。如果屏幕尺寸小于1000,“j”设置为1

var j = 0;
jQuery(document).ready(function(){
   if(j==0){
    console.log('enter function running');
    jQuery('ul[class^="nav-child"]').hide();
    jQuery('li[class^="item"]').one('mouseenter', function(){
      jQuery(this).find('ul').find('a').append('<br>');
      jQuery(this).find('ul').find('a').wrapAll('<div class="wrapper"></div>');
    });
    if(j==0){
      jQuery('li[class^="item"]').mouseenter(function(){
        console.log('first mouse enter / j = ' +j);
        if(j==0){
          jQuery(this).find('ul').fadeIn(0);
        }
      });
      jQuery('li[class^="item"]').mouseleave(function(){
        console.log('first mouse leave');
        if(j==0){
          jQuery(this).find('ul').fadeOut(0);
        }
      });
    }
    jQuery('li[class$="urrent"]').find('a').css('color', 'grey');
  }

});
jQuery(window).resize(function(){
  var screenWidth = jQuery(window).width();
  console.log('j=1');
  j = 1;
  console.log(screenWidth);
  if(screenWidth<1000){
    console.log('if running');
    console.log('hidden');
    jQuery('.nav').find('li').css('float', 'none');
    jQuery('.row-grey').css('height', 'auto');
    jQuery('ul[class^="nav-child"]').show();
    //jQuery('.wrapper').replaceWith('.wrapper-collapsed');
  }else{
    j=0;
    console.log('else running');
    jQuery('div[class$="ow-grey"]').children().show();
    jQuery('.nav').find('li').css('float', 'left');
    jQuery('ul[class^="nav-child"]').hide();
    jQuery('li[class^="item"]').one('mouseenter', function(){
    jQuery(this).find('ul').find('a').append(/*'<div class="stripe"></div>'*/'<br>');
    jQuery(this).find('ul').find('a').wrapAll('<div class="wrapper"></div>');
    });
    if(j==0){
      jQuery('li[class^="item"]').mouseenter(function(){
        jQuery(this).find('ul').fadeIn(0);
        console.log('mouseenter running');
      });
      jQuery('li[class^="item"]').mouseleave(function(){
        console.log('mouseleave running');
        jQuery(this).find('ul').fadeOut(0);
      });
      jQuery('li[class$="urrent"]').find('a').css('color', 'grey');
    }
  }
});
var j=0;
jQuery(文档).ready(函数(){
如果(j==0){
console.log('enter function running');
jQuery('ul[class^=“nav child”]').hide();
jQuery('li[class^=“item”]”)。一('mouseenter',function(){
jQuery(this).find('ul').find('a').append('
'); jQuery(this.find('ul').find('a').wrapAll(''); }); 如果(j==0){ jQuery('li[class^=“item”]”)。mouseenter(函数(){ log('first mouse enter/j='+j); 如果(j==0){ jQuery(this.find('ul').fadeIn(0); } }); jQuery('li[class^=“item”]”)。mouseleave(函数(){ log(“第一次鼠标离开”); 如果(j==0){ jQuery(this.find('ul').fadeOut(0); } }); } jQuery('li[class$=“current”]”)。find('a')。css('color','grey'); } }); jQuery(窗口).resize(函数(){ var screenWidth=jQuery(window).width(); console.log('j=1'); j=1; 控制台日志(屏幕宽度);
if(screenwidth)可能会添加一个JSFIDLE?或者添加HTML以便我可以重建它。我建议将您的代码简化为您正试图解决的问题。为什么您有很多
if(j==0){
?请重新排列您的代码,或者更好,为此创建一个or,@evolutionxbox我做了,但我不知道问题在这里面,否则代码就太多了longer@Louskac-我建议您研究一下。您甚至可以添加一个事件侦听器,并在不同大小匹配时运行代码。可以添加一个JSFIDLE?或添加HTML以便我可以重建它。我建议您将代码简化为您正试图解决的问题。如果(j==0),为什么会有很多
if{
?请重新排列您的代码,或者更好,为此创建一个or,@evolutionxbox我做了,但我不知道问题在这里面,否则代码就太多了longer@Louskac-我建议您研究一下。您甚至可以添加一个事件侦听器,并在不同大小匹配时运行代码。