-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.js
132 lines (71 loc) · 3.07 KB
/
menu.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
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
var ANIT_menu = function(){
var catalog, list;
this.rawSelector = '[data-type="menu-btn"]';
this.selector = this.rawSelector.substring(1,this.rawSelector.length-1);
this.btn = document.querySelector(this.rawSelector);
this.menu = document.querySelector('.nav-content');
this.switch = false;
this.list = document.querySelector('.nav-menu');
this.catalog = document.querySelector('.dpropdown-c');
this.btnBack = document.querySelector('[data-type="btn-back"]');
this.openMenu();
this.dropDown();
// Перелистнуть каталог
catalog = this.catalog;
catalog.addEventListener('click', function(){
ANIT_menu.list.style.marginLeft = '-100%';
ANIT_menu.list.classList.add('child-none');
}, ANIT_menu);
this.btnBack.addEventListener('click', function(){
ANIT_menu.list.style.marginLeft = '0%';
ANIT_menu.list.classList.remove('child-none');
}, ANIT_menu);
}
ANIT_menu.prototype.openMenu = function(){
// Открыть-закрыть меню
btn = this.btn; //Кнопка открывания и закрывания меню
list = this.list; // Контейнер с меню
catalog = this.catalog // кнопка открытия меню каталога
ANIT_menu = this;
function openMenu(){
if(ANIT_menu.switch === false){
ANIT_menu.menu.classList.add('active');
ANIT_menu.switch = true;
document.body.style.height = window.outerHeight + 'px';
document.body.style.overflow = 'hidden';
} else {
ANIT_menu.menu.classList.remove('active');
ANIT_menu.switch = false;
document.body.style.height = '';
document.body.style.overflow = '';
}
}
btn.addEventListener('click', openMenu, ANIT_menu);
function unify(e) { return e.changedTouches ? e.changedTouches[0] : e };
let x0 = null;
function lock(e) { x0 = unify(e).clientX };
let i = 0;
function move(e) {
if(x0 || x0 === 0) {
let dx = unify(e).clientX - x0, s = Math.sign(dx);
if((i > 0 || s < 0))
openMenu(ANIT_menu);
x0 = null
}
};
list.addEventListener('touchstart', lock, false);
list.addEventListener('touchend', move, ANIT_menu);
}
ANIT_menu.prototype.dropDown = function(){
var tree = document.querySelector('[data-type="anit-dropdown"]');
function ANIT_dropdown(){
if(event.target = 'li.dropdown'){
if(event.target.classList.contains('active')){
event.target.classList.remove('active')
} else {
event.target.classList.add('active')
}
}
}
tree.addEventListener('click', ANIT_dropdown, false);
}