0
Hello, I’m developing a little project using HTML/JS/CSS, which consists of changing the radius of the edge of an element, here an example: https://border-radius.com/
The problem is that I want the radius value of the border to change dynamically, without having to click the button for this event to happen.
function borderTopLeft() {
let bordertopleft = document.getElementById("border-top-left").value;
if(!bordertopleft) {
bordertopleft = 0;
}
document.getElementById("border").style.borderTopLeftRadius = `${bordertopleft}px`;
return;
}
function borderTopRight() {
let bordertopright = document.getElementById("border-top-right").value;
if(!bordertopright) {
bordertopright = 0;
}
document.getElementById("border").style.borderTopRightRadius = `${bordertopright}px`;
return;
}
function borderBottomRight() {
let borderbottomright = document.getElementById("border-bottom-right").value;
if(!borderbottomright) {
borderbottomright = 0;
}
document.getElementById("border").style.borderBottomRightRadius = `${borderbottomright}px`;
return;
}
function borderBottomLeft() {
let borderbottomleft = document.getElementById("border-bottom-left").value;
if(!borderbottomleft) {
borderbottomleft = 0;
}
document.getElementById("border").style.borderBottomLeftRadius = `${borderbottomleft}px`;
return;
}
function handleButton() {
borderTopLeft();
borderTopRight();
borderBottomRight();
borderBottomLeft();
}
* {
margin: auto;
text-align: center;
}
p {
margin-top: 100px;
height: 100px;
width: 150px;
padding: 10px;
background: #73AD21;;
}
input {
margin-top: 100px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Border-Radius Previewer</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<p id="border"></p>
<div id="inputAndButtons">
<input type="text" id="border-top-left" placeholder="Border top left" value="0">
<input type="text" id="border-top-right" placeholder="Border top right" value="0">
<input type="text" id="border-bottom-right" placeholder="Border bottom right" value="0">
<input type="text" id="border-bottom-left" placeholder="Border bottom left" value="0">
<button onclick="handleButton()" id="buttonBottomLeft">Apply</button>
</div>
<script src="index.js"></script>
</body>
</html>
Use the onKeyDown event on inputs. https://www.w3schools.com/jsref/event_onkeydown.asp
– Flavio Takeuchi
Da to use oninput in inputs.
– daniel