forked from arif-budianto/special-team
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
91 lines (83 loc) · 2.47 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
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
const btn = document.querySelector('.btn-gotop');
const tabbawah = document.querySelector('.tentang');
const container = document.querySelector('.root');
const layer = document.querySelector('.onload-screen');
// Pelatuk hamburger
function mobileMenu() {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
}
// Manipulasi elemen ketika web baru termuat
function onloadScreen() {
function toggleContainer() {
const isHidden = !container.style.display;
if (isHidden) {
container.style.display = 'none';
return;
}
container.style.display = null;
layer.textContent = 'Semoga Anda Tetap Bahagia';
}
toggleContainer();
setTimeout(toggleContainer, 2222);
setTimeout(() => layer.remove(), 4800);
}
// Tombol scroll ke atas, menampilkan
function btnToggle() {
const isScrolled = document.body.scroll > 20 || document.documentElement.scrollTop > 20;
if (isScrolled) {
btn.style.cssText = 'opacity: 1; visibility: visible;';
return;
}
btn.style.cssText = 'opacity: 0; visibility: hidden;';
}
// Tombol scroll ke atas, aksi
function scrollToTop() {
window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth'
});
}
// Aksi ketika DOM berhasil terload
document.addEventListener('DOMContentLoaded',
function () {
onloadScreen();
window.onscroll = btnToggle;
btn.onclick = scrollToTop;
hamburger.onclick = mobileMenu;
}
);
// Source code lama, Apriza Prasetio jadikan komentar dan ganti dengan source code di atas.
// function transitionLayer() {
// const test = document.querySelector('.test')
// const layer = document.querySelector('.layer');
// container.style.display = 'none';
// layer.style.display = 'block';
// setTimeout(() => {
// layer.style.display = 'none';
// container.style.display = 'block';
// }, 8000)
// setTimeout(() => {
// test.textContent = 'Semoga Anda Nyaman Disini'
// }, 4000);
// }
// function scrollToTop() {
// if (document.body.scroll > 20 || document.documentElement.scrollTop > 20) {
// btn.style.display = 'block'
// } else {
// btn.style.display = 'none'
// }
// }
// window.addEventListener('scroll', scrollToTop)
// btn.addEventListener('click', () => {
// window.scrollTo({
// top: 0,
// left: 0,
// behavior: 'smooth'
// });
// })
// window.addEventListener('DOMContentLoaded', transitionLayer)
// console.log('haloo')