Last active
December 16, 2019 18:11
-
-
Save rickklaasboer/2d396233e9098441421d510ec0feaa70 to your computer and use it in GitHub Desktop.
Revisions
-
rickklaasboer revised this gist
Dec 16, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ Add to HTML files (recommended place is below the opening `<body>` tag): ```html <button onclick="scrollToTop()" id="scrollToTop" style="display: none;" title="Go to top"> -
rickklaasboer revised this gist
Dec 16, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ Add to HTML files (recommended place is below the opening body tag): ```html <button onclick="scrollToTop()" id="scrollToTop" style="display: none;" title="Go to top"> -
rickklaasboer created this gist
Dec 16, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ Add to HTML files (recommended place is below the opening <body> tag): ```html <button onclick="scrollToTop()" id="scrollToTop" style="display: none;" title="Go to top"> <i class="fas fa-arrow-up"></i> </button> ``` Add to app.css (doesn't really matter where): ```css #scrollToTop { display: none; position: fixed; bottom: 20px; right: 30px; z-index: 99; border: none; outline: none; background-color: #00d1b2; color: white; cursor: pointer; padding: 15px; padding-right: 19px; padding-left: 19px; font-size: 18px; transition: all 0.2s ease-in-out; } #scrollToTop:hover { background-color: #00b89c; transition: all 0.2s ease-in; } ``` Add to app.js (doesn't really matter where): ```js window.addEventListener('scroll', () => { const button = document.getElementById('scrollToTop'); const scrollHeight = document.body.scrollTop || document.documentElement.scrollTop if (scrollHeight > 20) { button.style.display = "block"; } else { button.style.display = "none"; } }); scrollToTop = () => { window.scrollTo({ top: 0, behavior: 'smooth' }) } ```