jquery更改字体大小基于cookie? [英] jquery change font-size based on cookie?

查看:238
本文介绍了jquery更改字体大小基于cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个文本调整器,它还会根据用户选择的网站字体大小设置一个cookie。它创建cookie的罚款,但我似乎无法得到它来调整主体文本的大小,最初加载页面。任何帮助将不胜感激。

I'm trying to create a text resizer, which also sets a cookie depending on what the user has chosen as the font-size for the website. It creates the cookie fine, but I can't seem to get it to resize the body text once the page is loaded initially. Any help would be appreciated.

代码是:

  var origFont = parseFloat($("body").css("font-size"), 10);
  var cookieFont = $.cookie("fontSize");

  if (!cookieFont) {
    var curFont = origFont;
    $("#content").css("font-size", curFont);
  } else {
    var curFont = $.cookie("fontSize"); 
    $("#content").css("font-size", curFont);
  };

我使用相同的代码来改变字体大小,当你点击增加/

I am using the same code to change the font size when you click on increase/decrease, but it's not working for changing the body text once the page is loaded initially.

添加:我刚刚在IE中检查了它,它工作正常,但不是在FF,将检查其他浏览器现在...

ADDITION: I just checked this in IE and it works ok, but not in FF, will check the other browsers now...

确定这在IE和Opera,而不是Firefox,Chrome或Sarafi。

Ok this works in IE and Opera, but not Firefox, Chrome or Sarafi..

推荐答案

尝试定义单元

$("#content").css("font-size", curFont + 'px');

我在Firefox 3.6中测试了 font-size (如果没有单位,FF会自动添加 px ),而Chrome 9在没有单元的情况下无法工作。

I tested font-size in Firefox 3.6 and it does work without the unit (FF just appends px automatically if there's no unit), while Chrome 9 does not work without a unit.

这篇关于jquery更改字体大小基于cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆