How do I increase the font size based on the window width?

后端 未结 8 1319
一向
一向 2020-12-05 08:26

I am creating a web-based app that will be displayed on television and other large monitors. I am wanting a quick and easy way to increase the font size to fit the window si

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 08:53

    Here would be my approach (with removing actual classes + Drupal 7 jQuery):

    (function ($) {
    $(document).ready(function() {
    
    
    var bodyClassArr = new Array('extraWide', 'wide', 'normal', 'narrow', 'extraNarrow', 'mobile');
    
    function setBodyClass(){
      // remove previous classes
      for(x in bodyClassArr){
          if($('body').hasClass(bodyClassArr[x])){ $('body').removeClass(bodyClassArr[x]); }
      }
      var viewPortWidth = $(window).width();
      if (viewPortWidth > 1900) { $('body').addClass('extraWide'); }
      else if (viewPortWidth > 1400) { $('body').addClass('wide'); }
      else if (viewPortWidth > 1000) { $('body').addClass('normal'); }
      else if (viewPortWidth > 700) { $('body').addClass('narrow'); }
      else if (viewPortWidth < 700) { $('body').addClass('mobile'); }
      else { $('body').addClass('normal'); }
    };
    setBodyClass();
    
    $(window).resize(function() { setBodyClass(); });
    
    }); // jquery end
    }(jQuery));
    

提交回复
热议问题