jQuery – Dynamically change the font size of your website on run-time!

You might have seen some website have an option to increase and decrease the font size of the website by clicking an icon or link.

Same option you can have in your website too with the help of this simple jQuery Font resize Script!.

You can see the demo at the bottom of the page


<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var fontSize;

$("#insize").click(function(){
fontSize = parseInt($("p").css('font-size'));
fontSize = fontSize + 1 + "px";
$("p").css({'font-size':fontSize});
});
$("#desize").click(function(){
fontSize = parseInt($("p").css('font-size'));
fontSize = fontSize - 1 + "px";
$("p").css({'font-size' : fontSize});
});

});
</script>
</head>
<body>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<a href="#" id="insize">Increase Font Size</a>
<a href="#" id="desize">Decrease Font Size</a>
</body>
</html>

You can also see the demo here or just download and use it!

DemoDownload

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *