JavaScript - Dynamically Modify Element Radius
Submitted by razormist on Monday, September 2, 2019 - 11:23.
In this tutorial we will create a Dynamically Modify Element Radius using JavaScript. This code will change the border radius size when user drag the input range horizontally. The code use oninput() to initiate a function that dynamically change the border radius when the range input have been slide to modify the properties of the binded element . 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 Dynamically Modify Element Radius 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-6">
- <div class="form-group">
- <input type="range" oninput="changeRadius(this);" value="0" min="0" max="150"/>
- </div>
- <center>
- <div class="form-inline">
- <input type="text" id="slide_text" class="form-control" value="0" size="4" readonly="readonly"/>
- </div>
- </center>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will dynamically change the border radius when the range is moved. 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 changeRadius(slider){
- var input=document.getElementById("slide_text");
- input.value=slider.value;
- document.getElementById("target").style.borderRadius=slider.value+"px";
- }
Add new comment
- 94 views