-
Notifications
You must be signed in to change notification settings - Fork 1
/
blast_svg_en.html
48 lines (40 loc) · 1.15 KB
/
blast_svg_en.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
<!DOCTYPE HTML>
<!-- // Copyright 2002-2014, University of Colorado Boulder -->
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<!-- Localized title will be filled in by JavaScript. -->
<title>Blast SVG</title>
</head>
<body>
<svg width="50" height="50" id="rect">
<rect width="50" height="50" style="fill:rgb(255,0,0)"/>
</svg>
<script type="application/javascript">
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
let start = null;
const d = document.getElementById( 'rect' );
d.style.position = 'absolute';
let direction = 1;
let position = 100;
const speed = 3;
function step( timestamp ) {
if ( start === null ) {
start = timestamp;
}
position = position + speed * direction;
d.style.left = position + 'px';
requestAnimationFrame( step );
if ( position > 800 ) {
direction = -1;
}
else if ( position < 0 ) {
direction = 1;
}
}
requestAnimationFrame( step );
</script>
</body>
</html>