Smart Text Re-sizer ala jQuery (and cookies)


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

You'll need the latest version of [jQuery](http://www.jquery.com) and the jquery.cookie plugin([Snag it here!](http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/))


Copy this code and paste it in your HTML
  1. <script src="graphics/js/jquery-1.2.6.min.js" type="text/javascript"></script>
  2. <script src="graphics/js/jquery.cookie.js" type="text/javascript"></script>
  3. <script type="text/javascript" charset="utf-8">
  4. $(document).ready(function() {
  5. // See which font size the user wants
  6. $(".text a").click(function() {
  7. switch ($(this).attr("class")) {
  8. case 'small' : setFontSize(.8); break;
  9. case 'large' : setFontSize(1.6); break;
  10. case 'default' : setFontSize(1.2); break;
  11. }
  12. return false;
  13. });
  14.  
  15. // Set the font size and set a cookie
  16. function setFontSize(size) {
  17. $("#wrap, input, textarea").animate({fontSize: size+"em"}, 500).fadeIn("slow");
  18. createCookie(size);
  19. }
  20.  
  21. // Create and read coookies
  22. // Code functions by: Peter-Paul Koch
  23. // http://www.quirksmode.org/js/cookies.html
  24. function createCookie(value) {
  25. var date = new Date();
  26. date.setTime(date.getTime()+(30*24*60*60*1000));
  27. var expires = "; expires="+date.toGMTString();
  28. document.cookie = "font_size="+value+expires+"; path=/";
  29. }
  30. var font_size = $.cookie('font_size');
  31. if (font_size == '0.8') {
  32. $('#wrap').css("font-size",".8em");
  33. }
  34. if (font_size == '1.6') {
  35. $('#wrap').css("font-size","1.6em");
  36. }
  37. if (font_size == '1.2') {
  38. $('#wrap').css("font-size","1.2em");
  39. }
  40. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.