Log In

Email:
Password:
Keep me logged in

Forgot Password

Email:




Social Media
     
CategoriesCSS (5)
jQuery (73)
PHP (30)
.htaccess (4)
Sponsored Links


Font Increase/Decrease Button
CSS Javascript jQuery
Demo | Browse Category | Wednesday, January 11, 2012 by




jQuery:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
font_size = 16; //MUST BE OUTSIDE THE FUNTION, OTHER IT WILL ONLY INCREASE/DECREASE ONCE
function font(attr){

//CHANGES FONT SIZE ACCORDING TO BUTTON
if(attr=='inc'){
font_size += 2;
}
if(attr=='dec'){
font_size -= 2;
}

//KEEPS FONT SIZE FROM 2 TO 100
if(font_size<2){
font_size = 2;
}
if(font_size>100){
font_size = 100;
}

$("#text").css({"font-size":font_size+"px"}); //TEXT ALTERS HERE
$("#fs").html("Font-size: "+font_size); //(OPTIONAL) SHOWS FONT SIZE IN HTML
}
</script>
<style>
#text {
font-size: 16px;
word-wrap: break-word;
width: 600px;
}
</style>
</head>
<body>
<input id="inc" onClick="font($(this).attr('id'))" type="button" value="+">
<input id="dec" onClick="font($(this).attr('id'))" type="button" value="-">
<span id="fs"></span>
<div id="text">wcetdesigns.com</div>
</body>
</html>
Views: 142 Likes: 0 Dislikes: 0