Changing Body Font-Size based on Font-Family with jQuery

后端 未结 7 2070
日久生厌
日久生厌 2020-11-28 12:11

I\'m trying to use Myriad Pro as my primary font with Arial and such as a fall-back like so:

font: 13px \"Myriad Pro\", \"Helvetica\", \"Arial\", \"sans-seri         


        
相关标签:
7条回答
  • 2020-11-28 13:06

    JavaScript doesn't have an officially supported way of detecting fonts, but this library is a decent workaround: http://www.lalit.org/lab/javascript-css-font-detect

    Using this detector, you can then use:

    $(function(){
      var fontDetector = new Detector();
      if(fontDetector.test('Arial')){
        $('body').css('font-size', '10px');
      }
    });
    

    Also note that you should only change the font-size property. If you change the font property, you overwrite both your font size and your font families.

    0 讨论(0)
提交回复
热议问题