RequestAnimationFrame

Developer
Size
2,541 Kb
Views
10,120

How do I make an requestanimationframe?

What is a requestanimationframe? How do you make a requestanimationframe? This script and codes were developed by Martin Banks on 03 January 2023, Tuesday.

RequestAnimationFrame Previews

RequestAnimationFrame - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>requestAnimationFrame</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div></div> <script src="js/index.js"></script>
</body>
</html>

RequestAnimationFrame - Script Codes CSS Codes

div { width: 100px; height: 100px; background: red;
}

RequestAnimationFrame - Script Codes JS Codes

'use strict';
var start = null;
var element = document.querySelectorAll('div')[0];
var endPos = 500;
var duration = 2000;
/*
const interval = duration / 16
const increment = endPos / interval
var i = 0
const animate = setInterval(()=>{	//console.log(i)	element.innerHTML = increment * i	element.style.transform = `translateX(${i*increment }px)`	i+=16	if( i * increment === endPos ) {	clearInterval(animate)	console.log('stopped')	}
}, 100) */
function step(timestamp) {	if (!start) start = timestamp;	var progress = timestamp - start;	element.style.transform = '\n\t\ttranslate3d(' + Math.min(endPos * (progress / duration), endPos) + 'px, 0, 0 )';	if (progress < 2000) {	window.requestAnimationFrame(step);	}
}
window.requestAnimationFrame(step);
RequestAnimationFrame - Script Codes
RequestAnimationFrame - Script Codes
Home Page Home
Developer Martin Banks
Username martin-banks
Uploaded January 03, 2023
Rating 3
Size 2,541 Kb
Views 10,120
Do you need developer help for RequestAnimationFrame?

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!

Martin Banks (martin-banks) Script Codes
Create amazing Facebook ads with AI!

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!