smoth font resize


/ Published in: jQuery
Save to your folder(s)

need to be reviewed


Copy this code and paste it in your HTML
  1. /**************************************************************************************************
  2.  
  3. 8""""8 8"""" 8"""8
  4. 8 eeeeeee eeeee eeeee eeeee e e 8 eeeee eeeee eeeee 8 8 eeee eeeee e eeeee eeee
  5. 8eeeee 8 8 8 8 88 8 88 8 8 8 8eeee 8 88 8 8 8 8eee8e 8 8 " 8 " 8 8
  6.   88 8e 8 8 8 8 8 8 8e 8eee8 88 8 8 8e 8 8e 88 8 8eee 8eeee 8e eeee8 8eee
  7. e 88 88 8 8 8 8 8 8 88 88 8 88 8 8 88 8 88 88 8 88 88 88 88 88
  8. 8eee88 88 8 8 8eee8 8eee8 88 88 8 88 8eee8 88 8 88 88 8 88ee 8ee88 88 88ee8 88ee
  9.  
  10.   Script : Font resize (even smoother)
  11.   Version : 2
  12.   Authors : gordon
  13.  
  14.  
  15.   REQUIRES JQUERY
  16.   (testet with 1.3.2 min)
  17.  
  18. ***************************************************************************************************/
  19.  
  20. // Konfiguration:
  21.  
  22. // Zu verwenden mit folgendem Html
  23.  
  24. // <a class="changefontsize" rel="10" href="#" title="Schrift klein"><span>klein</span></a>
  25. // <a class="changefontsize" rel="" href="#" title="Schrift reset"><span>reset</span></a>
  26. // <a class="changefontsize" rel="20" href="#" title="Schrift groß"><span>groß</span></a>
  27.  
  28. // Vergrößert alles inerhalb: #content
  29.  
  30.  
  31. /***************************************************************************************************/
  32.  
  33. function initFontResize()
  34. {
  35. var orginalsize = $("#content").css("fontSize").substring(0, $("#content").css("fontSize").length-2);
  36. var orginallh = $("#content").css("lineHeight").substring(0, $("#content").css("lineHeight").length-2);
  37.  
  38. if(getCookie('atikonfontsize')!="")
  39. {
  40. setSize(getCookie('atikonfontsize'), orginalsize, orginallh, 1);
  41. }
  42. $(".changefontsize").click(function(){
  43. //Resetting
  44. if(!$(this).attr("rel"))
  45. {
  46. setSize(orginalsize, orginalsize, orginallh, 0);
  47. setCookie("atikonfontsize", "")
  48. }
  49. //Resizing
  50. else
  51. {
  52. setSize($(this).attr("rel"), orginalsize, orginallh, 0);
  53. }
  54. });
  55. }
  56. function setSize(size, orginalsize, orginallh, animationdisable)
  57. {
  58. if(size && orginalsize && orginallh)
  59. {
  60. // setCookie("atikonfontsize", size, "/")size
  61. document.cookie = "atikonfontsize="+size+"; path=/;";
  62. if(animationdisable == 1)
  63. {
  64. $("#content").css({fontSize: size+"px", lineHeight: Math.round( orginallh / ( orginalsize / size ) ) + "px" });
  65. return false;
  66. }
  67. $("#content").animate({fontSize: size+"px", lineHeight: Math.round( orginallh / ( orginalsize / size ) ) + "px" },600);
  68. }
  69. }
  70. $(document).ready(function() {
  71. initFontResize();
  72. });
  73. /*
  74.  COOCKIE FUNCTIONS
  75. */
  76. function getCookie(c_name)
  77. {
  78. if (document.cookie.length>0)
  79. {
  80. c_start=document.cookie.indexOf(c_name + "=");
  81. if (c_start!=-1)
  82. {
  83. c_start=c_start + c_name.length+1;
  84. c_end=document.cookie.indexOf(";",c_start);
  85. if (c_end==-1) c_end=document.cookie.length;
  86. return unescape(document.cookie.substring(c_start,c_end));
  87. }
  88. }
  89. return "";
  90. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.