-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
112 lines (87 loc) · 2.49 KB
/
script.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const displace = window.displacejs;
var font = JSON.parse(document.getElementById('font').innerHTML);
var textbox = Renderer.createTextbox({
font,
size: 100,
id: `textbox-_DF6G3`,
text: 'HAPPY\nBIRTHDAY'
});
for (var i=0; i<videoList.length; i++) {
addVid(videoList[i]);
}
var moveCount = 0;
var cancelClick = false;
var zInc = 11;
function addVid (name) {
var card = document.createElement('div');
card.setAttribute('id', name);
card.setAttribute('class', 'card');
var vidBox = document.createElement('div');
vidBox.setAttribute('class', 'vid-box');
card.appendChild(vidBox);
var vid = document.createElement('video');
vid.setAttribute('src', '/videos/'+name);
// vid.setAttribute('height', 300);
vid.setAttribute('loop', "true");
vidBox.appendChild(vid);
var shadow = document.createElement('div');
shadow.classList.add('shadow');
card.appendChild(shadow);
card.addEventListener('click', function(){
if (cancelClick) {
card.classList.remove('mousedown');
cancelClick = false;
return;
}
if (vid.paused) {
vid.play();
card.classList.add('playing');
}
else {
vid.pause();
card.classList.remove('playing');
}
})
card.addEventListener('mouseenter', function() {
// Animate card
if (!card.classList.contains('animating')) {
card.classList.add('animating');
setTimeout(function(){
card.classList.remove('animating');
}, 400);
}
// Increment z-index
var styleStrList = card.getAttribute('style').split(/z-index:.*;/);
styleStrList.push('z-index: ' + zInc++ +';');
var styleStr = styleStrList.join('');
card.setAttribute('style',styleStr);
});
card.addEventListener('mousedown', function() {
card.classList.add('mousedown');
});
card.addEventListener('mouseup', function() {
card.classList.remove('mousedown');
moveCount = 0;
});
var maxY = window.innerHeight - 300;
var maxX = window.innerWidth - 300;
card.setAttribute('style', 'left: '+maxX*Math.random()+'px; top: '+maxY*Math.random()+'px;');
document.querySelector('.cards-container').appendChild(card);
displace(card, {
constrain: true,
relativeTo: document.querySelector('.cards-container'),
onMouseMove: function() {
moveCount++;
if (moveCount > 10) cancelClick = true;
}
})
}
Renderer.start({
container: window,
data: {
textboxList: [textbox],
fontList: [font],
},
textureUrl: '/font-textures',
pixelRatio: 0.8
});