-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond_slideA_js.js
More file actions
53 lines (43 loc) · 1.4 KB
/
second_slideA_js.js
File metadata and controls
53 lines (43 loc) · 1.4 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
var pieces = 70,
speed = 1,
pieceW = 30,
pieceH = 30;
for (var i = pieces - 1; i >= 0; i--) {
$('#popup').prepend('<div class="piece" style="width:'+pieceW+'px; height:'+pieceH+'px"></div>');
};
function breakGlass(from){
if (from === "reverse"){
$('.piece').each(function(){
TweenLite.to($(this), speed, {x:0, y:0, rotationX:0, rotationY:0, opacity: 1, z: 0});
TweenLite.to($('#popup h1'),0.2,{opacity:1, delay: speed});
});
return;
}
if(!from){
TweenLite.to($('#popup h1'),0.2,{opacity:0});
} else {
TweenLite.from($('#popup h1'),0.5,{opacity:0, delay: speed});
}
$('.piece').each(function(){
var distX = getRandomArbitrary(-250, 250),
distY = getRandomArbitrary(-250, 250),
rotY = getRandomArbitrary(-720, 720),
rotX = getRandomArbitrary(-720, 720),
z = getRandomArbitrary(-500, 500);
if(!from){
TweenLite.to($(this), speed, {x:distX, y:distY, rotationX:rotX, rotationY:rotY, opacity: 0, z: z});
} else {
TweenLite.from($(this), speed, {x:distX, y:distY, rotationX:rotX, rotationY:rotY, opacity: 0, z: z});
}
});
}
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
$('.piece, h1').click(function(){
breakGlass();
});
$('.reverse').click(function(){
breakGlass('reverse');
});
breakGlass(true);