jquery, add/remove class when window width changes

前端 未结 7 1210
予麋鹿
予麋鹿 2020-11-27 13:26

I\'ve written out a very basic script to add/remove a class on load or when a window is resized.

I was just wondering if there was a better way of doing this or if i

7条回答
  •  失恋的感觉
    2020-11-27 13:52

    You Can also Use this Method I think its very clear to follow :

    $(window).on('resize', function(){
          var win = $(this);
          if (win.width() < 514) { 
    
          $('html').addClass('mobile');
    
          }
        else
        {
            $('html').removeClass('mobile');
        }
    
    });
    

    Simple Method

提交回复
热议问题