add null handling and fix merge conflicts

This commit is contained in:
Aaron Qian 2023-01-04 19:20:11 -08:00
parent 8580a1f463
commit 6e0a4b058d
No known key found for this signature in database
GPG key ID: BF1A987C395B5B0E
4 changed files with 37 additions and 34 deletions

View file

@ -40,19 +40,21 @@ window.addEventListener('DOMContentLoaded', () => {
// add scroll to top button
const btn = document.getElementById('scroll-to-top')
window.addEventListener('scroll', function () {
if (window.scrollY > 300) {
btn.classList.add('show')
} else {
btn.classList.remove('show')
}
})
btn.addEventListener('click', function (e) {
e.preventDefault()
window.scrollTo({
top: 0,
behavior: 'smooth'
if(btn) {
window.addEventListener('scroll', function () {
if (window.scrollY > 300) {
btn.classList.add('show')
} else {
btn.classList.remove('show')
}
})
})
btn.addEventListener('click', function (e) {
e.preventDefault()
window.scrollTo({
top: 0,
behavior: 'smooth'
})
})
}
})