-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
273 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,24 @@ | ||
//Event listener to see if scrolling has started | ||
|
||
window.addEventListener('scroll', function() { | ||
var element = document.getElementById('backToTopBtn'); | ||
var height = window.innerHeight; | ||
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; | ||
document.addEventListener('DOMContentLoaded', (event) => { | ||
let mybutton = document.getElementById("backToTopBtn"); | ||
|
||
if (scrollTop > height * 0.1) { // Adjust the 0.1 to control when the opacity starts changing | ||
element.style.opacity = 0.2; // 20% opacity | ||
element.style.display = "block" | ||
} else { | ||
element.style.opacity = 0; // 0% opacity | ||
element.style.display = "none" | ||
function topFunction() { | ||
document.body.scrollTop = 0; // For Safari | ||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | ||
mybutton.style.opacity = "75%"; | ||
} | ||
}); | ||
|
||
function backToTopBtn() { | ||
|
||
|
||
|
||
let mybutton = document.getElementById("backToTopBtn"); | ||
|
||
if (mybutton) { | ||
function topFunction() { | ||
document.body.scrollTop = 0; // For Safari | ||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | ||
mybutton.style.opacity = "75%"; | ||
} | ||
|
||
mybutton.onclick = topFunction; | ||
} | ||
|
||
// When the user scrolls down 20px from the top of the document, show the button | ||
window.onscroll = function() {scrollFunction()}; | ||
|
||
function scrollFunction() { | ||
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { | ||
mybutton.style.display = "block"; | ||
} else { | ||
mybutton.style.display = "none"; | ||
} | ||
} | ||
} | ||
}); |
This file contains 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 characters
Oops, something went wrong.