Skip to content

Commit

Permalink
refactor: remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
yilanboy committed Mar 6, 2024
1 parent 6a1e2c5 commit b49c7ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
33 changes: 20 additions & 13 deletions resources/ts/scroll-to-top-btn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,39 @@ window.setupScrollToTopButton = function (
): void {
scrollToTopButton.addEventListener('click', scrollToTop);

// 監聽滾動
window.addEventListener('scroll', () => {
if (window.scrollY > 0) {
scrollToTopButton.classList.add('xl:flex');
} else {
scrollToTopButton.classList.remove('xl:flex');
}
});

let header = <HTMLElement>document.getElementById('header');
let footer = <HTMLElement>document.getElementById('footer');

// 根據 header 是否出現在畫面上調整按鈕的樣式
let headerObserver = new IntersectionObserver(
function (entries) {
if (entries[0].isIntersecting) {
// header 在畫面上
scrollToTopButton.classList.remove('xl:flex');
} else {
// header 不在畫面上
scrollToTopButton.classList.add('xl:flex');
}
},
{ threshold: [0] },
);

// 根據 footer 是否出現在畫面上調整按鈕的樣式
let footerObserver = new IntersectionObserver(
function (entries) {
if (entries[0].isIntersecting) {
// footer 在畫面上
scrollToTopButton.classList.remove('fixed');
scrollToTopButton.classList.add('absolute');
scrollToTopButton.classList.remove('fixed', 'bottom-7');
scrollToTopButton.classList.add('absolute', 'bottom-1');
} else {
// footer 不在畫面上
scrollToTopButton.classList.add('fixed');
scrollToTopButton.classList.remove('absolute');
scrollToTopButton.classList.add('fixed', 'bottom-7');
scrollToTopButton.classList.remove('absolute', 'bottom-1');
}
},
{ threshold: [0] },
);

headerObserver.observe(header);
footerObserver.observe(footer);
};
4 changes: 2 additions & 2 deletions resources/views/components/post-form/ckedtior.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
editorDebounceTimer: null,
debounce(callback, time) {
// https://webdesign.tutsplus.com/tutorials/javascript-debounce-and-throttle--cms-36783
window.clearTimeout(this.editorDebounceTimer);
this.editorDebounceTimer = window.setTimeout(callback, time);
clearTimeout(this.editorDebounceTimer);
this.editorDebounceTimer = setTimeout(callback, time);
},
imageUploadUrl: @js(route('images.store')),
body: @entangle($model).live,
Expand Down

0 comments on commit b49c7ed

Please sign in to comment.