TEXT GROWING and TEXT SHRINKING program in javascript
Here you will learn that how to make TEXT GROWING and TEXT SHRINKING program in JavaScript using HTML language.
Program code to TEXT GROWING and TEXT SHRINKING
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <html> <head> <script language="javascript"> var minFont = 8; var maxFont = 18; function changeFontSize (addedSize) { // Get the current font size var currentFontSize = document.getElementById("mytext").style.fontSize; // Strip off the units, and the px currentFontSize = parseFloat(currentFontSize); // If the current fontSize is bigger than the max allowed, set it to // the max if (currentFontSize + addedSize > maxFont) document.getElementById("mytext").style.fontSize = maxFont + 'px'; // If the current fontSize is smaller than the min allowed, set it to // the min else if (currentFontSize + addedSize < minFont) document.getElementById("mytext").style.fontSize = minFont + 'px'; // Otherwise, just add the delta to the current size else document.getElementById("mytext").style.fontSize = currentFontSize + addedSize + 'px'; } </script> </head> <body> <h3>TEXT-SHRINKING and TEXT-GROWING Demo</h3> Text: <div id="mytext" style="font-size:14px;"> www.CodeRevise.com </div> <p> <button onclick="changeFontSize(1);">Grow</button> <button onclick="changeFontSize(-1);">Shrink</button> </p> </body> </html> |
Output
Check out our other JavaScript examples