JavaScript animation with setInterval
How do I make an javascript animation with setinterval?
What is a javascript animation with setinterval? How do you make a javascript animation with setinterval? This script and codes were developed by Mattia A Fritz on 26 August 2022, Friday.
JavaScript animation with setInterval - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>JavaScript animation with setInterval</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>JavaScript animation with setInterval()</h1>
<p> <label>Choose de "frame rate" from the list:</label> <select id="frameRate"> <option value="5">5 fps</option> <option value="15">15 fps</option> <option value="24" selected>24 fps</option> <option value="40">40 fps</option> <option value="60">60 fps</option> </select>
</p>
<p> <label>Choose the distance covered in every frame:</label> <select id="distance"> <option value="1">1px</option> <option value="5" selected>5px</option> <option value="10">10px</option> <option value="25">25px</option> <option value="50">50px</option> </select>
</p>
<div id="box"></div> <script src="js/index.js"></script>
</body>
</html>
JavaScript animation with setInterval - Script Codes CSS Codes
#box { width: 50px; height: 50px; border: 1px solid #000; background-color: darkorange;
}
JavaScript animation with setInterval - Script Codes JS Codes
var box = document.querySelector("#box");
var frameRate = document.querySelector("#frameRate");
var distance = document.querySelector("#distance");
var int;
function animate() { var margin = 0; int = setInterval(function() { margin = (margin > window.innerWidth ? 0 : margin + Number(distance.value)); box.style.marginLeft = margin + "px"; }, 1000 / Number(frameRate.value))
}
animate();
function reset() { clearInterval(int); animate();
}
frameRate.addEventListener("change", reset);
distance.addEvenetListener("change", reset);
Developer | Mattia A Fritz |
Username | mafritz |
Uploaded | August 26, 2022 |
Rating | 3 |
Size | 1,982 Kb |
Views | 34,408 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Utiliser dynamiquement des classes avec JavaScript | 2,005 Kb |
Three.ja animation example | 1,780 Kb |
JavaScript animation with requestAnimationFrame | 1,868 Kb |
P5.js example redefine draw function | 1,942 Kb |
Angular double binding example | 0 Kb |
Simple animation SVG avec JavaScript | 2,206 Kb |
CSS animation | 1,663 Kb |
P5.js example | 1,468 Kb |
P5.js example with button | 1,853 Kb |
Different size of columns according to screen size | 1,637 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Css Rotating 3d cubes different speed | Dghez | 2,364 Kb |
About Mazano | Kiti | 2,585 Kb |
Android Play Store With Slick Carousel | -J0hn- | 4,982 Kb |
Break Out | AzazelN28 | 12,431 Kb |
BSP Dungeon Generation | Xgundam05 | 5,326 Kb |
Transition | Shayhowe | 1,632 Kb |
How to add Css Fold Notes In Blogger By Askwithloud.com | Askwithloud | 2,280 Kb |
JS Countdown Timer | Ayoungh | 2,435 Kb |
Multiple jCarousel | Pafnuty | 2,461 Kb |
Svg animation draw | SzymonDziewonski | 5,545 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!