Repository navigation
Expand file tree
/
Copy pathtoggleSlider.js
More file actions
77 lines (55 loc) · 2.15 KB
/
Copy pathtoggleSlider.js
File metadata and controls
77 lines (55 loc) · 2.15 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
69
70
71
72
73
74
75
76
77
class ToggleSlider {
constructor() { }
init(p_mainElement)
{
this.mainElement = p_mainElement;
this.mainElement.classList.add("myToggle");
var sliderLine = document.createElement("div");
this.mainElement.classList.add("sliderLine");
this.mainElement.appendChild(sliderLine);
// <div id="mainToggle" class="myToggle">
// <div class="sliderLine" >
// </div>
// </div>
//var element = document.getElementById("mainToggle");
this.colors = [
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16),
"#" + Math.floor(Math.random()*16777215).toString(16)
];
for (let i = 0; i < 10; i++) {
var smalldiv = document.createElement("div");
smalldiv.classList.add("btnSmall");
smalldiv.style["background-color"] = this.colors[i];
var div = document.createElement("div");
div.classList.add("btn");
div.appendChild(smalldiv);
div.addEventListener("click", this.clickSlider.bind(this));
this.mainElement.appendChild(div);
}
var div = document.createElement("div");
div.classList.add("btnToggle");
div.id = "toggleSlider";
div.style.left = "0px";
div.style["background-color"] = this.colors[0];
this.mainElement.appendChild(div);
this.toggleSliderBtn = div;
}
clickSlider(event) {
var rect = event.target;
//alert (rect.style.top + " " + rect.style.left);
//alert (rect.offsetLeft);
//alert (rect.offsetLeft/30);
//var slider = document.getElementById("toggleSlider");
this.toggleSliderBtn.style.left = rect.offsetLeft + "px";
this.toggleSliderBtn.style["background-color"] = this.colors[rect.offsetLeft/30 || 0];
//alert (slider);
}
}