forked from daybrush/selecto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
96 lines (91 loc) · 2.78 KB
/
index.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
<!DOCTYPE html>
<html>
<style>
html,body {
position: relative;
height: 100%;
margin: 0;
padding: 0;
}
.target, .target2 {
position: absolute;
background: #faa;
box-sizing: border-box;
}
.target.selected {
border: 4px solid #f55;
}
.button {
position: absolute;
left: 500px;
top: 50px;
background: #eee;
padding: 15px 40px;
display: inline-block;
border-radius: 5px;
font-weight: bold;
color: #444;
}
.button.selected {
color: #fff;
background: #66d;
}
</style>
<body>
<div class="button"> Shift </div>
<div class="target" style="top: 50px; left: 50px; width: 50px; height: 50px">T1</div>
<div class="target" style="top: 50px; left: 150px; width: 150px; height: 50px">T2</div>
<div class="target" style="top: 150px; left: 50px; width: 100px; height: 50px">T3</div>
<div class="target" style="top: 300px; left: 250px; width: 50px; height: 150px">T4</div>
<div class="target" style="top: 200px; left: 400px; width: 100px; height: 100px">T5</div>
<div class="target2" style="top: 330px; left: 80px; width: 120px; height: 120px" contenteditable="true">T7</div>
</body>
<script src="../../dist/selecto.js"></script>
<div class="hi"></div>
<script>
const selecto = new Selecto({
container: document.body,
// rootContainer: document.body,
// boundContainer: true,
// ratio: 1,
dragCondition: () => false,
hitRate: 40,
selectableTargets: [".target"],
selectFromInside: true,
selectByClick: true,
checkInput: true,
toggleContinueSelect: "shift",
}).on("dragStart", e => {
console.log("ds", e.inputEvent.target);
}).on("drag", e => {
selecto.findSelectableTargets();
}).on("selectStart", e => {
console.log("start", e);
e.added.forEach(el => {
el.classList.add("selected");
});
e.removed.forEach(el => {
el.classList.remove("selected");
});
}).on("selectStart", () => {
setTimeout(() => {
document.body.insertAdjacentHTML("beforeend", `<div class="target" style="top: 300px; left: 50px; width: 50px; height: 50px">T6</div>`);
});
}).on("selectEnd", e => {
if (e.isDouble) {
console.log("dblclick");
}
console.log("end", e);
e.afterAdded.forEach(el => {
el.classList.add("selected");
});
e.afterRemoved.forEach(el => {
el.classList.remove("selected");
});
}).on("keydown", () => {
document.querySelector(".button").classList.add("selected");
}).on("keyup", () => {
document.querySelector(".button").classList.remove("selected");
});
</script>
</html>