Repository navigation
Expand file tree
/
Copy pathCSSPlugin.html
More file actions
80 lines (61 loc) · 2.66 KB
/
Copy pathCSSPlugin.html
File metadata and controls
80 lines (61 loc) · 2.66 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<title>TweenJS: CSS Tweening Example</title>
<link href="../_assets/css/shared.css" rel="stylesheet" type="text/css"/>
<link href="../_assets/css/examples.css" rel="stylesheet" type="text/css"/>
<link href="../_assets/css/tweenjs.css" rel="stylesheet" type="text/css"/>
<script src="../_assets/js/examples.js" type="text/javascript"></script>
<script type="text/javascript" src="../lib/tweenjs-NEXT.js"></script>
<!-- We also provide hosted minified versions of all CreateJS libraries.
http://code.createjs.com -->
<script type="text/javascript" src="../src/tweenjs/plugins/CSSPlugin.js"></script>
<!-- We also provide hosted minified versions of all CreateJS libraries.
http://code.createjs.com -->
<script id="editable">
var colorSeed = 0;
function init() {
createjs.CSSPlugin.install();
var count = 300;
while (--count >= 0) {
// create a new box:
var box = document.createElement("div");
box.style.width = "1%";
box.style.height = "4%";
box.style.position = "absolute";
box.style.borderRadius = "2px";
box.style.backgroundColor = "#0F0";
box.style.opacity = 0;
document.body.appendChild(box);
// set up initial rotation & position:
var a = (Math.random() * Math.PI * 2 * 16 | 0) / 16;
box.style.transform = "translate(-50%,-50%) translate(50vw,50vh) rotate(" + a + "rad)";
var d = 5;
box.style.left = Math.cos(a) * d + "vh";
box.style.top = Math.sin(a) * d + "vh";
// calculate the target position:
d = Math.random()*20+20;
var x = Math.cos(a) * d;
var y = Math.sin(a) * d;
// create the tween:
// CSSPlugin will use the value suffix it initially finds on the target's style.
// So in this case, top/left use "vh", width/height use "%" and opacity has no suffix.
createjs.Tween.get(box, {loop: -1}, true).wait(Math.random() * 2000| 0).to({opacity:1}).call(updateColor).to({top: y, left: x, width: 10, height: 0, opacity: 0.6}, Math.random() * 500 + 500, createjs.Ease.quadInOut);
}
// tween the base color that divs will be assigned when they start moving:
createjs.Tween.get(this, {loop: -1}).to({colorSeed: 360}, 5000);
createjs.Ticker.timingMode = createjs.Ticker.RAF;
}
function updateColor(tween) {
// grab the tween's target (the style object), and update it's color
tween.target.style.backgroundColor = "hsl(" + (Math.random() * 60 + colorSeed | 0) + ",100%,50%)";
}
</script>
</head>
<body onload="init();" style="background-color:#111111; overflow:hidden">
<header class="TweenJS">
<h1>CSS Plugin Example</h1>
<p>The CSS Plugin tweens CSS values on HTML DOM elements, and handles unit suffixes (such as px).</p>
</header>
</body>
</html>