Skip to content

Commit c591752

Browse files
authored
Merge pull request #105 from nadyakhrns/master
Menambahkan Scroll ke atas atau Scroll to top dan Dark Mode
2 parents 066e35a + 22dc121 commit c591752

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

belajarpython_theme/css/base.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,4 +1373,20 @@ main kbd {
13731373
font-size: 1.5rem;
13741374
line-height: 2rem;
13751375
}
1376-
}
1376+
1377+
// style button scrollToTop
1378+
#scrollToTop {
1379+
font-size: 16px;
1380+
transition: background-color 0.3s;
1381+
}
1382+
1383+
#scrollToTop:hover {
1384+
background-color: #333;
1385+
}
1386+
}
1387+
1388+
// dark mode
1389+
body.dark-mode {
1390+
background-color: #121212;
1391+
color: #ffffff;
1392+
}

belajarpython_theme/footer.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
<a target="_blank" href="https://goo.gl/forms/ZPyZgIagXcanYwzH2">Contact</a>
77
</div>
88
</div>
9-
</footer>
9+
10+
// dark Mode
11+
<button id="toggleDarkMode" style="position: fixed; bottom: 20px; right: 20px; z-index: 99;">
12+
🌙 Dark Mode
13+
</button>
14+
15+
</footer>

belajarpython_theme/js/base.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,47 @@ $(document).ready(function() {
154154
});
155155
});
156156

157+
// Scroll to the top
158+
// Get the button
159+
let scrollToTopButton = document.getElementById("scrollToTop");
160+
161+
// Show button when user scrolls down
162+
window.onscroll = function () {
163+
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
164+
scrollToTopButton.style.display = "block";
165+
} else {
166+
scrollToTopButton.style.display = "none";
167+
}
168+
};
169+
170+
// Scroll to top when button is clicked
171+
scrollToTopButton.onclick = function () {
172+
document.body.scrollTop = 0; // For Safari
173+
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE, and Opera
174+
};
175+
176+
// dark mode
177+
const darkModeButton = document.getElementById('toggleDarkMode');
178+
179+
// Cek apakah user sudah pernah memilih mode sebelumnya
180+
if (localStorage.getItem('darkMode') === 'enabled') {
181+
document.body.classList.add('dark-mode');
182+
darkModeButton.textContent = '☀️ Light Mode';
183+
}
184+
185+
// Tambahkan event listener untuk tombol
186+
darkModeButton.addEventListener('click', () => {
187+
if (document.body.classList.contains('dark-mode')) {
188+
document.body.classList.remove('dark-mode');
189+
localStorage.setItem('darkMode', 'disabled'); // Simpan preferensi user
190+
darkModeButton.textContent = '🌙 Dark Mode';
191+
} else {
192+
document.body.classList.add('dark-mode');
193+
localStorage.setItem('darkMode', 'enabled'); // Simpan preferensi user
194+
darkModeButton.textContent = '☀️ Light Mode';
195+
}
196+
});
197+
157198
$(window).on('resize', applyTopPadding);
158199

159200
$('body').scrollspy({

belajarpython_theme/scrollUp.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<button id="scrollToTop" style="display: none; position: fixed; bottom: 20px; right: 20px; z-index: 99; border: none; outline: none; background-color: #555; color: white; cursor: pointer; padding: 10px; border-radius: 5px;">
2+
&#8679; Scroll Up
3+
</button>

0 commit comments

Comments
 (0)