JavaScript - Dynamic Font Resizer
Submitted by razormist on Tuesday, October 2, 2018 - 21:28.
In this tutorial we will create a Dynamic Font Resizer using JavaScript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is a text-based programming language meant to run as part of a web-based application. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding...
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/.Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it 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="form-inline">
- <input type="number" id="size" class="form-control"/>
- </div>
- <br />
- <p id="result" style="text-align:justify; text-justify: inter-word;">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.</p>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will change the font size dynamically based on user input. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder.- function resizeFont(){
- var size = document.getElementById('size');
- if(size.value.length > 0){
- var result = document.getElementById('result');
- result.style.fontSize = size.value+"px";
- size.value = "";
- }else{
- alert("Please enter something first!");
- }
- }
Add new comment
- 32 views