forked from nmaurin/developpement_web_avance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_1.html
49 lines (43 loc) · 985 Bytes
/
test_1.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
<DOCTYPE html!>
<html>
<!-- Code html -->
<head>
<meta charset="utf-8" />
<title>L'animation avec SetInterval-1</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 = 800;
var timer;
timer = setInterval(function() {
console.log(left);
pausecomp(100);
elem.style.left = left + "px";
left -= 10;
if( left < 0 ) {
clearInterval( timer );
}
},16); //on perd l'image toute les 16ms. Ce qui ne ralenti pas l'action.
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>