-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
164 lines (145 loc) · 4.15 KB
/
main.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
// Navbar/Sidebar
const menuBtn=document.querySelectorAll('.menu-btn');
const menu=document.querySelector('.menu');
const links=document.querySelectorAll('.menu li');
// Toggle sidebar open/close
menuBtn.forEach(btn=>{
btn.addEventListener('click', sideNavToggle);
});
function sideNavToggle(){
// Animation delay
let delay = 100;
//Toggle open class
menu.classList.toggle('menu-open');
// Sidenav Link Slide Animations
setTimeout(()=>{
// Reset animations after all of them end
resetAnimations();
}, delay*(links.length+1));
// Add animation to links
links.forEach(link=>{
// Opacity
link.style.opacity="0";
// Animation
link.style.animation="slideIn 400ms ease-in-out forwards";
// Delay
link.style.animationDelay=delay+"ms";
// Increase delay for each link
delay+=100;
});
// Reset animations so they can be activated again
function resetAnimations(){
// Select all links
links.forEach(link=>{
// Remove animations
link.style.animation="none";
// Set opacity back to default
link.style.opacity="1";
});
}
}
// Slider
const cntrl=document.querySelectorAll('.slider-cntrl');
const cntrlMob=document.querySelectorAll('.pagination-mobile > li');
const title=document.querySelector('.title');
const subTitle=document.querySelectorAll('.sub-title');
const img=document.querySelector('.thumbnail');
const count=document.querySelector('.slider-count');
const progress=document.querySelector('.progress div');
let id=0;
// Data
// Array with image paths for the slider
const images=['img/img1.jpg', 'img/img2.jpg', 'img/img3.jpg',];
// Progress widths for the slider
const progressWidth=[
'33%', '66%', '100%',
];
// Text variations for the slider
const text=[
'Work',
'Active',
'Travel',
];
// Pagination Controls
for(let i=0; i<cntrl.length; i++){
// Add click event for all pagination
cntrl[i].addEventListener('click', ()=>{
// Run the slider function
slider(i);
// Set id to clicked pagination index
id=i;
// Stop Auto Slide
stopAutoSlide();
});
// Add click event for all pagination on mobile
cntrlMob[i].addEventListener('click',()=>{
// Run the slider function
slider(i);
// Set id to cclicked pagination index
id=i;
// Stop Auto Slide
stopAutoSlide();
});
}
function slider(i){
// Change thumbnail image
img.src=images[i];
// Progress progression
progress.style.width=progressWidth[i];
// Change title
title.innerHTML=text[i]+" Collection";
// Change Sub Title
subTitle.forEach(sub=>{
sub.innerText=text[i]+" Collection"
});
// Change slide number
count.innerText="/0"+(i+1);
// Remove active class from all
for(let i=0; i<cntrl.length; i++){
cntrl[i].classList.remove('active');
cntrlMob[i].classList.remove('pag-active');
}
// Reset acitve class to clicked element
cntrl[i].classList.add('active');
cntrlMob[i].classList.add('pag-active');
}
// Slider Automation
function nextSlide(){
// Increment img id
id++;
// Check if if is greater than the number of available slides
if(id>cntrl.length-1){
id=0;
}
// Run the slider fucntion
slider(id);
}
// Automatic Sldier
let autoSlide=setInterval(nextSlide, 10000);
// Stop Automatic slide
function stopAutoSlide(){
clearInterval(autoSlide);
// Restart Auto Slider
autoSlide=setInterval(nextSlide, 10000);
}
// disabling inspect element
document.addEventListener("contextmenu", function(e){
e.preventDefault(); //this prevents right click
});
document.onkeydown=function(e){
if(event.keycode==123){
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode=="I".charCodeAt(0)){
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode=="C".charCodeAt(0)){
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode=="J".charCodeAt(0)){
return false;
}
if(e.ctrlKey && e.keyCode=="U".charCodeAt(0)){
return false;
}
};