Ezeewp – making wordress easy for you
contact us contact us contact us contact us contact us

"Developing WordPress themes, templates and WordPress plugins"

Increase font size on the page with JQuery

Wednesday 23rd December 2009 by admin

0

COMMENTS

jquery-logoGiving visitors to your site the ability to increase font size on the page – it’s available in most browsers tool bars – is one way to help accessibility and usability on your blog /  site.

It can be easily achieved using a small bit of JQuery. Sounds complex, but with JQuery already built into WordPress all you need do is add this function into the header file (code setion 1) and add a little bit of text and CSS – (code section 2)

Code section 1

  1. $(document).ready(function(){
  2.  
  3. // Reset Font Size
  4.  
  5. var originalFontSize = $(‘html’).css(‘font-size’);
  6.  
  7. $(".resetFont").click(function(){ $(‘html’).css(‘font-size’, originalFontSize); });
  8.  
  9. // Increase Font Size
  10.  
  11. $(".increaseFont").click(function(){
  12.  
  13. var currentFontSize = $(‘html’).css(‘font-size’);
  14.  
  15. var currentFontSizeNum = parseFloat(currentFontSize, 10);
  16.  
  17. var newFontSize = currentFontSizeNum*1.2;
  18.  
  19. $(‘html’).css(‘font-size’, newFontSize);
  20.  
  21. return false;
  22.  
  23. });
  24.  
  25. // Decrease Font Size
  26.  
  27. $(".decreaseFont").click(function(){
  28.  
  29. var currentFontSize = $(‘html’).css(‘font-size’);
  30.  
  31. var currentFontSizeNum = parseFloat(currentFontSize, 10);
  32.  
  33. var newFontSize = currentFontSizeNum*0.8;
  34.  
  35. $(‘html’).css(‘font-size’, newFontSize);
  36.  
  37. return false;
  38.  
  39. });
  40.  
  41. });
  42.  

Code section 2

  1.  
  2. <div id="textsizing">
  3.  
  4. Font size:
  5.  
  6. <a class="increaseFont" title="Make text larger" href="#">Increase</a>
  7.  
  8. <a class="decreaseFont" title="Make text smaller" href="#">Decrease</a>
  9.  
  10. <a class="resetFont" title="Return to default size" href="#">Reset</a></div>
  11.  
  12.  

Once again, hope this helps

Popularity: 4% [?]

Please leave a response and trackback from your own site.

Leave a Reply