-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathScript.js
193 lines (166 loc) · 5.27 KB
/
Script.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
const slides=document.querySelector(".slider").children;
const prev=document.querySelector(".prev");
const next=document.querySelector(".next");
const indicator=document.querySelector(".indicator");
let index=0;
prev.addEventListener("click",function(){
prevSlide();
updateCircleIndicator();
resetTimer();
})
next.addEventListener("click",function(){
nextSlide();
updateCircleIndicator();
resetTimer();
})
// create circle indicators
function circleIndicator(){
for(let i=0; i< slides.length; i++){
const div=document.createElement("div");
div.innerHTML=i+1;
div.setAttribute("onclick","indicateSlide(this)")
div.id=i;
if(i==0){
div.className="active";
}
indicator.appendChild(div);
}
}
circleIndicator();
function indicateSlide(element){
index=element.id;
changeSlide();
updateCircleIndicator();
resetTimer();
}
function updateCircleIndicator(){
for(let i=0; i<indicator.children.length; i++){
indicator.children[i].classList.remove("active");
}
indicator.children[index].classList.add("active");
}
function prevSlide(){
if(index==0){
index=slides.length-1;
}
else{
index--;
}
changeSlide();
}
function nextSlide(){
if(index==slides.length-1){
index=0;
}
else{
index++;
}
changeSlide();
}
function changeSlide(){
for(let i=0; i<slides.length; i++){
slides[i].classList.remove("active");
}
slides[index].classList.add("active");
}
function resetTimer(){
// when click to indicator or controls button
// stop timer
clearInterval(timer);
// then started again timer
timer=setInterval(autoPlay,5000);
}
function autoPlay(){
nextSlide();
updateCircleIndicator();
}
let timer=setInterval(autoPlay,4000);
(() =>{
const openNavMenu = document.querySelector(".open-nav-menu"),
closeNavMenu = document.querySelector(".close-nav-menu"),
navMenu = document.querySelector(".nav-menu"),
menuOverlay = document.querySelector(".menu-overlay"),
mediaSize = 991;
openNavMenu.addEventListener("click", toggleNav);
closeNavMenu.addEventListener("click", toggleNav);
// close the navMenu by clicking outside
menuOverlay.addEventListener("click", toggleNav);
function toggleNav() {
navMenu.classList.toggle("open");
menuOverlay.classList.toggle("active");
document.body.classList.toggle("hidden-scrolling");
}
navMenu.addEventListener("click", (event) =>{
if(event.target.hasAttribute("data-toggle") &&
window.innerWidth <= mediaSize){
// prevent default anchor click behavior
event.preventDefault();
const menuItemHasChildren = event.target.parentElement;
// if menuItemHasChildren is already expanded, collapse it
if(menuItemHasChildren.classList.contains("active")){
collapseSubMenu();
}
else{
// collapse existing expanded menuItemHasChildren
if(navMenu.querySelector(".menu-item-has-children.active")){
collapseSubMenu();
}
// expand new menuItemHasChildren
menuItemHasChildren.classList.add("active");
const subMenu = menuItemHasChildren.querySelector(".sub-menu");
subMenu.style.maxHeight = subMenu.scrollHeight + "px";
}
}
});
function collapseSubMenu(){
navMenu.querySelector(".menu-item-has-children.active .sub-menu")
.removeAttribute("style");
navMenu.querySelector(".menu-item-has-children.active")
.classList.remove("active");
}
function resizeFix(){
// if navMenu is open ,close it
if(navMenu.classList.contains("open")){
toggleNav();
}
// if menuItemHasChildren is expanded , collapse it
if(navMenu.querySelector(".menu-item-has-children.active")){
collapseSubMenu();
}
}
window.addEventListener("resize", function(){
if(this.innerWidth > mediaSize){
resizeFix();
}
});
})();
$(function() {
$('.btn-posnawr')
.on('mouseenter', function(e) {
var parentOffset = $(this).offset(),
relX = e.pageX - parentOffset.left,
relY = e.pageY - parentOffset.top;
$(this).find('span').css({top:relY, left:relX})
})
.on('mouseout', function(e) {
var parentOffset = $(this).offset(),
relX = e.pageX - parentOffset.left,
relY = e.pageY - parentOffset.top;
$(this).find('span').css({top:relY, left:relX})
});
$('[href=#]').click(function(){return false});
});
// counter section
$(document).ready(function() {
$('.counter').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
});