jquery change font-size based on cookie?

放肆的年华 提交于 2019-12-23 14:49:09

问题


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.

The code is:

  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.

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

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


回答1:


Try defining a unit.

Something like

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

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.




回答2:


You are missing the +"px"

See working demo here:

http://jsbin.com/ufetu5/2/edit



来源:https://stackoverflow.com/questions/4963985/jquery-change-font-size-based-on-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!