0

我正在尝试在设置宽度之前和之后添加和删除类,一旦宽度小于 1140,addclass 和 remove 类就可以正常工作,但是当 with 大于 1140 时,删除类和添加类 dosnt 工作。如果我能得到任何帮助,我真的会非常感激它。

jQuery(document).ready(function($){


    var low = false;
    $(document).ready(function() {
    var pageWidth = $(window).width();
    if (pageWidth <= 1140) {
        low = true;
        $('.studio .thirtyheight').removeClass('thirtyheight').addClass('workfullheight');
        $('.studio .sixtyheight').removeClass('sixtyheight').addClass('workfullheighttwo');
    }

    $(window).resize(function() {
        if ($(window).width() <= 1140) {
            if (!low) {
                low = true;
                $('.studio .thirtyheight').removeClass('thirtyheight').addClass('workfullheight');
                $('.studio .sixtyheight').removeClass('sixtyheight').addClass('workfullheighttwo');
            }
        }
        else if (low) {
            low = false;
             $('.studio .workfullheight').addClass('thirtyheight').removeClass('workfullheight');
             $('.studio .workfullheighttwo').addClass('sixtyheight').removeClass('workfullheighttwo');
        }
    });
});




});
4

2 回答 2

1

你忘了其他情况

使用它然后它会工作

var $window = $(window),
      $html = $('.studio .thirtyheight'),
      $htmltwo = $('.studio .sixtyheight');
        if ($window.width() < 1140) {
          return $html.addClass('workfullheight').removeClass('thirtyheight'),      
          $htmltwo.addClass('workfullheighttwo').removeClass('sixtyheight');
        }else{
          $html.removeClass('workfullheight').addClass('thirtyheight'), 
          $htmltwo.removeClass('workfullheighttwo').addClass('sixtyheight');
}      
于 2013-08-22T10:24:11.203 回答
0
jQuery(document).ready(function($){


var low = false;
$(document).ready(function() {
    var pageWidth = $(window).width();
    if (pageWidth <= 1140) {
        low = true;
        $('.studio .thirtyheight').removeClass('thirtyheight').addClass('workfullheight');
        $('.studio .sixtyheight').removeClass('sixtyheight').addClass('workfullheighttwo');
    }

    $(window).resize(function() {
        if ($(window).width() <= 1140) {
            if (!low) {
                low = true;
                $('.studio .thirtyheight').removeClass('thirtyheight').addClass('workfullheight');
                $('.studio .sixtyheight').removeClass('sixtyheight').addClass('workfullheighttwo');
            }
        }
        else if (low) {
            low = false;
             $('.studio .workfullheight').addClass('thirtyheight').removeClass('workfullheight');
             $('.studio .workfullheighttwo').addClass('sixtyheight').removeClass('workfullheighttwo');
        }
    });
});




});
于 2013-08-23T10:47:43.760 回答