-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyself.js
71 lines (67 loc) · 2.67 KB
/
myself.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
var _Dropdown = (function() {
var Dropdown = function(div, li, i, none) {
this.div = div;
this.li = li;
this.i = i;
this.none = none;
this.mouseover();
this.mouseleave();
this.click();
}
Dropdown.prototype.click = function() {
this.li = Array.prototype.slice.call(this.li)
var _this = this;
this.div.addEventListener("click", function(e) {
if (e.target.tagName.toLowerCase() === "li") {
_this.li.forEach(function(idx, element) {
idx.classList.remove("addbg");
});
if (e.target.className.toLowerCase() == "third") {
_this.i.classList.add("addi");
_this.none.forEach(function(element) {
element.classList.remove("none");
}, this);
}
e.target.classList.add("addbg");
}
})
}
Dropdown.prototype.mouseover = function() {
this.li = Array.prototype.slice.call(this.li)
var _this = this;
this.div.addEventListener("mouseover", function(e) {
if (e.target.tagName.toLowerCase() === "li") {
_this.li.forEach(function(idx, element) {
idx.classList.remove("addbg");
});
if (e.target.className.toLowerCase() == "third") {
_this.i.classList.add("addi");
_this.none.forEach(function(element) {
element.classList.remove("none");
}, this);
}
e.target.classList.add("addbg");
}
})
}
Dropdown.prototype.mouseleave = function() {
var _this = this;
this.none = Array.prototype.slice.call(this.none)
this.div.addEventListener("mouseleave", function() {
_this.li.forEach(function(element) {
element.classList.remove("addbg");
});
_this.i.classList.remove("addi");
_this.none.forEach(function(element) {
element.classList.add("none");
}, this);
})
}
return {
init: function(div, li, i, none) {
new Dropdown(div, li, i, none);
}
}
})()
var a = new _Dropdown.init(document.getElementsByTagName("div")[0], document.getElementsByTagName("li"), document.getElementsByTagName(
"i")[0], document.getElementsByClassName("none"));