forked from rammcodes/WowFolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
141 lines (107 loc) Β· 4.09 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
const smMenuBtn = document.querySelector('.main-header__sm-scr-nav-btn')
const smMenu = document.querySelector('.main-header__sm-menu')
const smMenuCloseBtn = document.querySelector('.main-header__sm-menu-close')
const smMenuLinks = document.querySelectorAll('.main-header__sm-menu-link')
const smMenuLink1 = document.querySelector('.main-header__sm-menu-link--1')
const smMenuLink2 = document.querySelector('.main-header__sm-menu-link--2')
const smMenuLink3 = document.querySelector('.main-header__sm-menu-link--3')
const smMenuLink4 = document.querySelector('.main-header__sm-menu-link--4')
smMenuBtn.addEventListener('click', () => {
smMenu.style.transitionDelay = '0s'
smMenu.classList.add('main-header__sm-menu--active')
smMenuLink1.style.transitionDelay = '.5s'
smMenuLink1.style.transform = 'translateY(0)'
smMenuLink1.style.opacity = '1'
smMenuLink2.style.transitionDelay = '.8s'
smMenuLink2.style.transform = 'translateY(0)'
smMenuLink2.style.opacity = '1'
smMenuLink3.style.transitionDelay = '1.1s'
smMenuLink3.style.transform = 'translateY(0)'
smMenuLink3.style.opacity = '1'
smMenuLink4.style.transitionDelay = '1.4s'
smMenuLink4.style.transform = 'translateY(0)'
smMenuLink4.style.opacity = '1'
})
smMenuLinks.forEach((ele) => {
ele.addEventListener('click', () => {
smMenuLink4.style.transitionDelay = '0s'
smMenuLink4.style.transform = 'translateY(50px)'
smMenuLink4.style.opacity = '0'
smMenuLink3.style.transitionDelay = '.3s'
smMenuLink3.style.transform = 'translateY(50px)'
smMenuLink3.style.opacity = '0'
smMenuLink2.style.transitionDelay = '.6s'
smMenuLink2.style.transform = 'translateY(50px)'
smMenuLink2.style.opacity = '0'
smMenuLink1.style.transitionDelay = '.9s'
smMenuLink1.style.transform = 'translateY(50px)'
smMenuLink1.style.opacity = '0'
smMenu.style.transitionDelay = '1.2s'
smMenu.classList.remove('main-header__sm-menu--active')
setTimeout(() => {
document.getElementById(ele.name).scrollIntoView()
}, 1300)
})
})
smMenuCloseBtn.addEventListener('click', () => {
smMenuLink4.style.transitionDelay = '0s'
smMenuLink4.style.transform = 'translateY(50px)'
smMenuLink4.style.opacity = '0'
smMenuLink3.style.transitionDelay = '.3s'
smMenuLink3.style.transform = 'translateY(50px)'
smMenuLink3.style.opacity = '0'
smMenuLink2.style.transitionDelay = '.6s'
smMenuLink2.style.transform = 'translateY(50px)'
smMenuLink2.style.opacity = '0'
smMenuLink1.style.transitionDelay = '.9s'
smMenuLink1.style.transform = 'translateY(50px)'
smMenuLink1.style.opacity = '0'
smMenu.style.transitionDelay = '1.2s'
smMenu.classList.remove('main-header__sm-menu--active')
})
// ---
const themeColorSelector = document.querySelector('.themeClrSelector')
const themeColorSelectorInput = document.querySelector(
'.themeClrSelector__input'
)
const root = document.documentElement;
const hexToRgb = (hex) => {
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
}
: null
}
const eventFire = (el, etype) => {
if (el.fireEvent) {
el.fireEvent('on' + etype)
} else {
let evObj = document.createEvent('Events')
evObj.initEvent(etype, true, false)
el.dispatchEvent(evObj)
}
}
themeColorSelector.addEventListener('click', () => {
eventFire(themeColorSelectorInput, 'input')
})
const setDynamicColor = (color) => {
const { r, g, b } = hexToRgb(`${color}`)
root.style.setProperty('--themeColor', `${r},${g},${b}`);
//localStorage.setItem('color', color)
}
themeColorSelectorInput.addEventListener('input', (e) => {
setDynamicColor(e.target.value)
})
// if (localStorage.getItem('color')) {
// let userSelectedColor = localStorage.getItem('color')
// themeColorSelectorInput.value = userSelectedColor
// setDynamicColor(userSelectedColor)
// }
// ---
const headerLogoConatiner = document.querySelector('.main-header__logo-container')
headerLogoConatiner.addEventListener('click', () => {
location.href = 'index.html'
})