我有一些代码可以增加/减小字体大小。这让我很头疼,因为每个浏览器似乎以不同的方式实现 $.css('font-size')
(查看 jquery 错误)。不过,真正让我烦恼的是,Firefox 的缩放比例还不错,但当我使用下面的缩小功能时,它就会放大。 Webkit 和IE 都按预期工作。对此有什么想法吗?
我把它放在这里的小提琴中: http://jsfiddle.net/srQ3P/1/ 你在哪里可以看到它按预期工作,并且您可以在项目页面的 Firefox 中看到它损坏: http://cumberlandme.info/residents
主要编辑
抱歉,问题不是代码,而是 Firefox 的 bug 行为。当我使用浏览器控件(ctrl + plus 或 ctrol + minus)放大或缩小后,js 就会变得混乱。在其他浏览器中不会发生这种情况。这才是真正的问题。对此有什么建议吗?
I've got some code to increase/decrease font size. This is giving me a headache because each browser seems to implement the $.css('font-size')
differently (see jquery bug). The part that's really killing me, though, is that Firefox is scaling up okay, but when I use the scale down function below, it scales up. Webkit & IE are both working as expected. Any ideas on that?
I put this in a fiddle here: http://jsfiddle.net/srQ3P/1/ where you can see it working as expected, and you can see it broken in firefox at the project page: http://cumberlandme.info/residents
MAJOR EDIT
Sorry, the issue is not the code, it's firefox buggy behavior. After I zoom in or out with the browser controls (ctrl + plus or ctrol + minus) the js goes haywire. This doesn't happen in other browsers. This is the real issue. Any advice on that
发布评论
评论(1)
本例中的问题出在我的 javascript 文本缩放功能上。我使用的原始函数(在网上找到)在正文字体样式中查找特定的 em 值,如果没有找到,请将字体大小重置为“1em”。就像这样:
这在 IE 上可以正常工作(为什么,我不知道),但在 Ffx 上却不行。因此,我提出的解决方案是检查 IE,并根据浏览器是否为 IE,执行的操作略有不同。 jQuery 文档建议不要以这种方式检查浏览器,这是毫无意义的,但我还是这么做了!
The problem in this case was with my javascript text zooming function. The original function I used (found online) looked for a specific em value in the body font style and if it did not find one, reset the font size to '1em'. Like so:
This worked (why, I don't know) okay on IE, but not Ffx. So the solution I came up with checks for IE and does things slightly differently based on if the browser is IE or not. It's worth nothing that the jQuery docs recommend against checking for the browser in this way, but I did it anyway!