diff --git a/src/scripts/modules/backToTop/backToTop.ts b/src/scripts/modules/backToTop/backToTop.ts deleted file mode 100644 index 08761991..00000000 --- a/src/scripts/modules/backToTop/backToTop.ts +++ /dev/null @@ -1,19 +0,0 @@ -export function backToTop() { - const button: HTMLDivElement = document.createElement( 'div' ); - button.setAttribute( 'id', 'backtotop' ); - const scrollToTop = () => { - window.scrollTo( 0, 0 ); - }; - button.onclick = scrollToTop; - document.body.appendChild( button ); - window.addEventListener( 'scroll', () => { - if ( - window.scrollY >= - ( document.body.scrollHeight - window.innerHeight ) / 2 - ) { - document.body.classList.remove( 'above-the-fold' ); - } else { - document.body.classList.add( 'above-the-fold' ); - } - } ); -} diff --git a/src/scripts/modules/backToTop/index.ts b/src/scripts/modules/backToTop/index.ts new file mode 100644 index 00000000..3229c0e7 --- /dev/null +++ b/src/scripts/modules/backToTop/index.ts @@ -0,0 +1,12 @@ +export function backToTop() { + const button: HTMLDivElement = document.createElement( 'div' ); + button.setAttribute( 'id', 'backtotop' ); + const scrollToTop = () => { + window.scrollTo( { + top: 0, + behavior: 'smooth', + } ); + }; + button.onclick = scrollToTop; + document.body.appendChild( button ); +} diff --git a/src/scripts/modules/scrollControl/index.ts b/src/scripts/modules/scrollControl/index.ts index fa0b9ee0..7f7edbf5 100644 --- a/src/scripts/modules/scrollControl/index.ts +++ b/src/scripts/modules/scrollControl/index.ts @@ -27,6 +27,12 @@ function scrollCallback() { } } + if ( Ypos >= ( document.body.scrollHeight - window.innerHeight ) / 2 ) { + document.body.classList.remove( 'above-the-fold' ); + } else { + document.body.classList.add( 'above-the-fold' ); + } + if ( Ypos < 5 ) { document.body.classList.add( 'top' ); } else { diff --git a/src/scripts/scripts.ts b/src/scripts/scripts.ts index 2fcb970e..1a0d537e 100644 --- a/src/scripts/scripts.ts +++ b/src/scripts/scripts.ts @@ -6,7 +6,7 @@ import { modulrMasonryController } from './modules/masonry'; import { modulrSelectController } from './modules/select'; import { modulrGrid } from './modules/grid'; import { modulrScrollTo } from './modules/scroll/scroll'; -import { backToTop } from './modules/backToTop/backToTop'; +import { backToTop } from './modules/backToTop'; window.addEventListener( 'DOMContentLoaded', async () => { /* enable scroll animations */