forked from nmaurin/developpement_web_avance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_3.html
49 lines (43 loc) · 953 Bytes
/
test_3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<html>
<!-- Code html -->
<head>
<meta charset="utf-8" />
<title>L'animation avec requestAnimationFrame-3</title>
</head>
<body>
<div id="animatedElem"></div>
</body>
<!--Code CSS -->
<style>
#animatedElem {
position:absolute;
width:100px;
height:100px;
background:red;
left:400px;
}
</style>
<!-- Code JS -->
<script type="text/javascript">
var elem = document.getElementById("animatedElem");
var left = 400;
var debut = 400;
var delta = debut-left;
var m =10;
function step(timestamp) {
pausecomp(m);
elem.style.left = (left -=10) + "px";
if(left >= 0) {
requestAnimationFrame(step);
}
}
requestAnimationFrame(step);
function pausecomp(millis) { //simulation d'une grosse fonction infulent sur la fuliditée des autres actions.
var date = new Date();
var curDate = null;
do {
curDate = new Date();
}while(curDate-date < millis);
}
</script>
</html>