-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
68 lines (59 loc) · 1.64 KB
/
index.html
File metadata and controls
68 lines (59 loc) · 1.64 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
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>drag.js</title>
<style>
#box {
background-color: darkslategray;
height: 200px;
width: 200px;
}
#box.draggable {
cursor: move;
}
#box.dragged {
background-color: darksalmon;
}
#text {
background: #242424;
color: #fff;
padding: .5em;
text-align: center;
}
</style>
</head>
<body>
<div id="box">
<div id="text">You can drag for <span id="time"></span> seconds.</div>
</div>
<script src="drag.js"></script>
<script>
const $box = document.getElementById("box");
const drag = new Drag($box);
drag.on("start", function () {
$box.classList.add("dragged");
});
drag.on("end", function() {
$box.classList.remove("dragged");
});
drag.activate();
$box.classList.add("draggable");
/* counter */
const $text = document.getElementById("text");
const $time = document.getElementById("time");
let sec = 10;
$time.innerHTML = sec;
const timer = window.setInterval(function () {
$time.innerHTML = --sec;
if (sec <= 0) {
$text.innerHTML = "You can't drag anymore.";
drag.deactivate();
$box.classList.remove("draggable");
window.clearInterval(timer);
}
}, 1000);
</script>
</body>
</html>