forked from ruthmann/CMSDPuzzleCards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_v2.html
210 lines (173 loc) · 5.62 KB
/
index_v2.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
index_v2.html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CMSD Aeolus Hunt Puzzle Cards</title>
<style>
.card {
display: block;
width: 267px;
height: 209px;
border-radius: 20px;
border: solid 1px black;
background-color: #fff;
}
.card img {
width: 100%;
height: 100%;
border-radius: inherit;
}
#cardtray {
list-style: none;
width: 135px;
position: absolute;
left: 0;
margin: 10px;
padding: 0;
}
#cardtray li {
margin: 0 0 10px 0;
}
#cardtray .card {
width: 133.5px;
height: 104.5px;
border-radius: 10px;
cursor: pointer;
}
#cardlist {
margin-left: 155px;
padding: 0;
}
#cardlist li {
display: inline-block;
width: 267px;
height: 209px;
border: 3px solid #555;
margin: 10px;
border-radius: 20px;
cursor: pointer;
vertical-align: top;
}
#cardlist li.empty {
border-style: dashed;
border-color: #999;
background-color: #f6f6f6;
}
#cardlist li.over {
border-color: dodgerblue;
background-color: aliceblue;
}
#cardlist li.current {
border-color: orange;
box-shadow: 0 0 30px rgba(255, 165, 0, 0.15);
}
#cardlist li .card {
border: 0;
}
</style>
<script>
var music;
var timings = [0, 2.65, 5.39, 8.03, 10.72, 13.62, 15.95, 18.76, 21.54, 24.13, 26.52];
function handleDragStart(e) {
//this.style.opacity = '0.4'; // this / e.target is the source node.
console.log('drag start');
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', this.outerHTML);
}
function handleDragEnter(e) {
// this / e.target is the current hover target.
this.classList.add('over');
}
function handleDragOver(e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
return false;
}
function handleDragLeave(e) {
this.classList.remove('over'); // this / e.target is previous target element.
}
function handleDrop(e) {
e.stopPropagation();
this.classList.remove('over');
this.classList.remove('empty');
this.innerHTML = e.dataTransfer.getData('text/html');
this.querySelector('div.card').setAttribute('draggable', 'false');
return false;
}
window.onload = function() {
music = document.getElementById('music');
var cards = document.querySelectorAll('.card');
Array.prototype.forEach.call(cards, function(card) {
card.addEventListener('dragstart', handleDragStart, false);
});
var slots = document.querySelectorAll('#cardlist li');
Array.prototype.forEach.call(slots, function(slot, index) {
slot.addEventListener('dragenter', handleDragEnter, false);
slot.addEventListener('dragover', handleDragOver, false);
slot.addEventListener('dragleave', handleDragLeave, false);
slot.addEventListener('drop', handleDrop, false);
slot.addEventListener('click', function(evt) {
music.currentTime = timings[index];
music.play();
});
});
document.addEventListener('keydown', function(event) {
// If the delete key has been pressed
if(event.keyCode == 46) {
var selected = document.querySelector('.current');
if(selected) {
selected.innerHTML = '';
selected.classList.add('empty');
}
}
});
updateTiming();
}
function updateTiming() {
var current = document.querySelector('li.current');
if(current) {
current.classList.remove('current');
}
if(!music.paused) {
var index = 0;
for(var i = 0; i < timings.length; ++i) {
if(music.currentTime >= timings[i]) {
index = i;
}
}
document.querySelectorAll('#cardlist li')[index].classList.add('current');
}
window.requestAnimationFrame(updateTiming);
}
</script>
</head>
<body>
<center><h2>String Quartet No.1 in B flat major, Op.1 'Hunt' (opening excerpt)</h2>
<i>Franz Joseph Haydn (1732 † 1809)</i>
<p><audio id="music" src="huntaeolus.mp3" preload="auto" loop="loop" controls="controls"/></p>
</center>
<ul id="cardtray">
<li><div class="card" draggable="true" ><img draggable="false" src="img/card1.png" alt="" /></div></li>
<li><div class="card" draggable="true" ><img draggable="false" src="img/card2.png" alt="" /></div></li>
<li><div class="card" draggable="true" ><img draggable="false" src="img/card3.png" alt="" /></div></li>
<li><div class="card" draggable="true" ><img draggable="false" src="img/card4.png" alt="" /></div></li>
<li><div class="card" draggable="true" ><img draggable="false" src="img/card5.png" alt="" /></div></li>
<li><div class="card" draggable="true" ><img draggable="false" src="img/card6.png" alt="" /></div></li>
<li><div class="card" draggable="true" ><img draggable="false" src="img/card7.png" alt="" /></div></li>
<li><div class="card" draggable="true" ><img draggable="false" src="img/card8.png" alt="" /></div></li>
</ul>
<ul id="cardlist">
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
<li class="empty"></li>
</ul>
</body>
</html>