-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
191 lines (147 loc) · 4.93 KB
/
index.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
//preloader
const counter = document.getElementById('preloader-counter');
const preloader = document.getElementById('preloader');
setTimeout(()=> {
counter.innerText = '30%';
}, 250)
setTimeout(()=> {
counter.innerText = '68%';
}, 750)
setTimeout(()=> {
counter.innerText = '87%';
}, 1000)
setTimeout(()=> {
counter.innerText = '100%';
}, 1500)
setTimeout(()=> {
preloader.style.display = 'none';
}, 2000)
//slider
let isDown = false;
let startX;
let scrollLeft;
const slider = document.querySelector('.slider-inner');
const end = () => {
isDown = false;
slider.classList.remove('active');
}
const start = (e) => {
isDown = true;
slider.classList.add('active');
startX = e.pageX || e.touches[0].pageX - slider.offsetLeft;
scrollLeft = slider.scrollLeft;
}
const move = (e) => {
if(!isDown) return;
e.preventDefault();
const x = e.pageX || e.touches[0].pageX - slider.offsetLeft;
const dist = (x - startX);
slider.scrollLeft = scrollLeft - dist;
}
slider.addEventListener('mousedown', start);
slider.addEventListener('touchstart', start);
slider.addEventListener('mousemove', move);
slider.addEventListener('touchmove', move);
slider.addEventListener('mouseleave', end);
slider.addEventListener('mouseup', end);
slider.addEventListener('touchend', end);
// scroll-to-top
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
const upArrow = document.getElementById('arrow-up');
upArrow.addEventListener('click', topFunction);
// mobile nav
const line = document.querySelector('.line');
const mobileNavOpen = document.querySelector('.mobile-nav-open');
const body = document.querySelector('body');
line.addEventListener('click', ()=> {
mobileNavOpen.classList.toggle('block');
body.classList.toggle('stop-scrolling');
})
const close = document.getElementById('close');
close.addEventListener('click', ()=> {
mobileNavOpen.classList.toggle('block');
body.classList.toggle('stop-scrolling');
})
// testimonials
const data = [
{
name:'Jamie K Cohen',
quote: 'Déplacé Maison is a convincer for anticipation. The urban trekking as nevers seen before. An exceptional product that has no equal alongside a great team represent the brand professionally.'
},
{
name:'William Gibson',
quote:'Good things come to those who wait – Déplacé Maison is what has been missing in the modern fashion industry for years. Buy a shoe of high quality and design it finally happened.'
}
]
let i = 0;
let testimonialName = document.querySelector('.testimonial-name');
let testimonialQuote = document.querySelector('.testimonial-quote');
const timer = setInterval(()=> {
if(i > 1){
i = 0;
}
testimonialName.innerText = data[i].name;
testimonialQuote.innerText = data[i].quote;
i++;
}, 5000)
// Ink Mode
const inkToggle = document.getElementById('ink-mode');
let verticalLogo = document.querySelector('.vertical-logo');
let newsletterLogo = document.querySelector('.newsletter');
let facebookLogo = document.getElementById('facebook');
let instagramLogo = document.getElementById('instagram');
inkToggle.addEventListener('click', ()=> {
body.classList.toggle('ink');
if(body.classList.contains('ink')){
verticalLogo.src = 'images/ink-logo-vert.svg';
newsletterLogo.src = 'images/newsletter-side.svg';
upArrow.src = 'images/arrow-up-ink.svg';
facebookLogo.src = 'images/facebook2.svg';
instagramLogo.src = 'images/instagram2.svg';
} else {
verticalLogo.src = 'images/de-logotype-vert.svg';
newsletterLogo.src = 'images/newsletter-face.svg';
upArrow.src = 'images/arrow-up.svg';
facebookLogo.src = 'images/facebook1.svg';
instagramLogo.src = 'images/instagram1.svg';
}
})
//cursor
const TAIL_LENGTH = 20;
const cursor = document.getElementById('cursor');
let mouseX = 0;
let mouseY = 0;
let cursorCircles;
let cursorHistory = Array(TAIL_LENGTH).fill({x: 0, y: 0});
function onMouseMove(event) {
mouseX = event.clientX;
mouseY = event.clientY;
}
function initCursor() {
for (let i = 0; i < TAIL_LENGTH; i++) {
let div = document.createElement('div');
div.classList.add('cursor-circle') ;
cursor.append(div);
}
cursorCircles = Array.from(document.querySelectorAll('.cursor-circle'));
}
function updateCursor() {
cursorHistory.shift();
cursorHistory.push({ x: mouseX, y: mouseY });
for (let i = 0; i < TAIL_LENGTH; i++) {
let current = cursorHistory[i];
let next = cursorHistory[i + 1] || cursorHistory[TAIL_LENGTH - 1];
let xDiff = next.x - current.x;
let yDiff = next.y - current.y;
current.x += xDiff * 0.35;
current.y += yDiff * 0.35;
cursorCircles[i].style.transform = `translate(${current.x}px, ${current.y}px) scale(${i/TAIL_LENGTH})`;
}
requestAnimationFrame(updateCursor)
}
document.addEventListener('mousemove', onMouseMove, false);
initCursor();
updateCursor();