Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
131 lines (115 loc) · 4.38 KB
/
Copy pathscript.js
File metadata and controls
131 lines (115 loc) · 4.38 KB
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
// ----------- About Tabs -----------
const tabsContainer = document.querySelector(".about-tabs"),
aboutSection = document.querySelector(".about-section");
tabsContainer.addEventListener("click", (e) =>{
if(e.target.classList.contains("tab-item") && !e.target.classList.contains("active")){
tabsContainer.querySelector(".active").classList.remove("active");
e.target.classList.add("active");
const target = e.target.getAttribute("data-target");
aboutSection.querySelector(".tab-content.active").classList.remove("active");
aboutSection.querySelector(target).classList.add("active");
}
});
// Fullscreen Mode
document.addEventListener("DOMContentLoaded", function () {
// Fullscreen button
const btn = document.createElement("button");
btn.textContent = "Enter Fullscreen?";
btn.style.position = "fixed";
btn.style.top = "10px";
btn.style.right = "10px";
btn.style.zIndex = "9999";
btn.style.padding = "10px 20px";
btn.style.borderRadius = "10px";
btn.style.border = "none";
btn.style.backgroundColor = "#e02f6b";
btn.style.color = "white";
btn.style.cursor = "pointer";
btn.style.boxShadow = "0 0 10px rgba(0,0,0,0.3)";
btn.style.fontFamily = "inherit";
// Add to page
document.body.appendChild(btn);
// When clicked
btn.addEventListener("click", function () {
const masuk = confirm("Want to open in fullscreen mode?");
if (!masuk) return;
// Request Fullscreen
const docEl = document.documentElement;
const request =
docEl.requestFullscreen ||
docEl.webkitRequestFullscreen ||
docEl.msRequestFullscreen;
if (request) {
request.call(docEl)
.then(() => {
// Successful fullscreen entry -> remove button.
btn.remove();
})
.catch(() => {
// Failed to enter fullscreen -> the button can remain.
alert("Gagal masuk ke fullscreen.");
});
} else {
alert("Browser tidak mendukung fullscreen.");
}
});
// If the user presses esc to exit fullscreen -> the button can appear again.
document.addEventListener("fullscreenchange", function () {
if (!document.fullscreenElement && !document.getElementById("fullscreen-btn")) {
document.body.appendChild(btn);
}
});
});
// Fullscreen Mode End
// Portofolio Item Details Popup
document.addEventListener("click", (e) => {
if(e.target.classList.contains("view-project-btn")){
togglePortofolioPopup();
// document.querySelector(".portofolio-popup").scrollTo(0,0);
portofolioItemDetails(e.target.parentElement);
}
})
function togglePortofolioPopup(){
document.querySelector(".portofolio-popup").classList.toggle("open")
document.body.classList.toggle("hide-scrolling");
document.querySelector(".main").classList.toggle("fade-out");
}
document.querySelector(".pp-close").addEventListener("click", togglePortofolioPopup);
// hide popup when click img outside of it
document.addEventListener("click", (e) => {
if(e.target.classList.contains("pp-inner")){
togglePortofolioPopup();
}
});
function portofolioItemDetails(portofolioItem){
document.querySelector(".pp-thumbnail img").src =
portofolioItem.querySelector(".portofolio-item-thumbnail img").src;
document.querySelector(".pp-header h3").innerHTML =
portofolioItem.querySelector(".portofolio-item-title").innerHTML;
document.querySelector(".pp-body").innerHTML =
portofolioItem.querySelector(".portofolio-item-details").innerHTML;
}
// BARU [UPDATE]
// Function to observe sections and add 'active' class
function observeSections() {
const sections = document.querySelectorAll('section');
const options = {
root: null, // viewport
threshold: 0.5, // 50% of the section must be visible
rootMargin: "0px"
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('active');
} else {
entry.target.classList.remove('active');
}
});
}, options);
sections.forEach(section => {
observer.observe(section);
});
}
// Call the function when the document is ready
document.addEventListener('DOMContentLoaded', observeSections);