JavaScript - Dynamic Font Resizer
Submitted by razormist on Tuesday, April 9, 2019 - 16:01.
In this tutorial we will create a Dynamic Font Resizer using JavaScript. This code can change the font size to any part of the web page dynamically. The code use onclick function to put up a switch statement to determine the case value in order to rewritten the font size of the web page text. Feel free to modify and apply it in your system, this is a user-friendly kind of program
We will be using JavaScript as a server-side scripting language because It gives a greater control of your web page and extend its capability in a modern way approach. It is written in HTML or as an external sourcing to add some necessary features in your website.
There you have it we successfully created a Dynamic Font Resizer using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting started:
First you have to download bootstrap framework, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-8">
- <div class="form-inline">
- <select class="form-control" id="size">
- </select>
- </div>
- <br />
- <div id="result" class="col-md-12" style="height:200ox; border:1px solid #000;">
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse blandit molestie lobortis. Donec at quam quam. Sed iaculis ut libero quis feugiat. Donec risus ipsum, malesuada eu sodales eu, pretium ac est. In nec lacinia arcu. Sed congue, nibh vel fringilla finibus, turpis lectus condimentum lectus, ultrices iaculis enim mauris eget sapien. Integer ultrices sit amet elit sed vestibulum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum dapibus, erat et hendrerit laoreet, dolor dolor finibus tortor, eget tempus eros purus nec neque. Nunc dictum neque consequat aliquam ornare. Nulla facilisi. Proin id ex in ante molestie laoreet sed tempor quam. In tristique sem leo, nec scelerisque libero interdum id. Pellentesque non leo dolor. Nullam ac auctor metus. Fusce faucibus quam id suscipit accumsan.
- </div>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will dynamically change the web page text when the button is clicked. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.- function resize(){
- var size = document.getElementById('size').value;
- var text = document.getElementById('result');
- switch(size){
- case "8pt":
- text.style.fontSize = "8px";
- break;
- case "10pt":
- text.style.fontSize = "10px";
- break;
- case "11pt":
- text.style.fontSize = "11px";
- break;
- case "12pt":
- text.style.fontSize = "12px";
- break;
- case "14pt":
- text.style.fontSize = "14px";
- break;
- case "16pt":
- text.style.fontSize = "16px";
- break;
- case "18pt":
- text.style.fontSize = "18px";
- break;
- }
- }
Add new comment
- 41 views