简体   繁体   English

javascript font-reizer在IE8或IE7中不起作用

[英]javascript font-resizer not working in IE8 or IE7

I'm trying to create a site-wide font resizer, but most of the implementations seem to want me to target elements by id or class, instead of site-wide. 我正在尝试创建一个站点范围内的字体大小调整器,但是大多数实现似乎都希望我按id或class而不是站点范围内的元素为目标。

I'm trying to do accomplish my task by setting up my pages starting with this CSS: 我试图通过设置以以下CSS开头的页面来完成任务:

  • html = 83% html = 83%
  • body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,p,blockquote,th,td,etc... = 1em 正文,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,p,blockquote,th,td等... = 1em

Then, I have some jquery that grabs the currently applied font-size, increases it and re-applies it. 然后,我有一些jquery可以获取当前应用的font-size,增加它并重新应用它。

But it's not working in IE8 or IE7. 但是它在IE8或IE7中不起作用。 (shocker) (震惊)

var currentFontSize = $('html').css('font-size');
var currentFontSizeNum = parseFloat(currentFontSize, 10);
var newFontSize = currentFontSizeNum*1.05;
$("html").css('cssText', 'font-size: ' + newFontSize + 'px !important');

If I console.log out the values, it's computing fine in those browsers, but there seems to be something about relative font sizing in those browsers. 如果我用console.log登出这些值,则在这些浏览器中可以正常运行,但是在这些浏览器中似乎存在相对字体大小的问题。 I also tried resetting everything to 100%, instead of 1em, but that didn't work, either. 我还尝试将所有内容重置为100%,而不是1em,但这也不起作用。

Example jsfiddle (but this site doesn't work in ie8 or below.....) jsfiddle示例(但是此站点在ie8或更低版本中无法工作.....)

You are applying the size without any unit. 您要应用的尺寸没有任何单位。 Add px to the size: px添加到大小:

$('html').css('font-size', newFontSize + 'px');

Side note: the parseFloat function doesn't take any radix parameter: 旁注: parseFloat函数不使用任何基数参数:

var currentFontSizeNum = parseFloat(currentFontSize);

I couldn't get it to work in IE8 & IE7, so I changed my code to apply a class to the html object (body would work, too). 我无法在IE8和IE7中使用它,因此我更改了代码以将一个类应用于html对象(主体也可以使用)。 Then, in the IE8 & IE7 css files, I have styles that are listening for those classes and adjust their sizes, accordingly. 然后,在IE8和IE7 css文件中,我有监听这些类并相应调整其大小的样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM