Monday, March 21, 2011

Proportionate Text Zoomer - Javascript

Hi,

In this I have made a custom script which can be used in any website to increase or decrease the text size of the entire page. You can find the entire source code at the end of this post. The zoom in and zoom out functionality is performed irrespective of their current font size. e.g. if a span has font size 10 and h1 as 14, then this will make span to 11 and h1 to 15, based on a certain percentage.

This is what the sample page looks like:

In this script you can choose tags whose text needs to be increased/decreased. This is what you have to do in script.js to add a new tag to have the functionality:


  $(".increaseFont").click(function(){  // for increasing font

$('a').each(function(idx, item) {    //adding the funtionality to anchor tag
       size=parseInt(jQuery(this).css("font-size"));
  size++;
  jQuery(this).css("font-size",size + "px")
    });
})

 $(".decreaseFont").click(function(){  // for decreasing text size
   $('a').each(function(idx, item) {   //adding the funtionality to anchor tag
       size=parseInt(jQuery(this).css("font-size"));
  size--;
  jQuery(this).css("font-size",size + "px")
    });
})

Click here to download the source code.

No comments:

Post a Comment