I'm facing an issue with two scripts on my website - when they are separate, they work perfectly fine but together, they don't seem to function properly. What could I be missing here?
Script 1:
window.onscroll = function() {myFunction()};
var navigation = document.getElementById("navigation");
var sticky = navigation.offsetTop;
function myFunction() {
if (window.pageYOffset > sticky) {
navigation.classList.add("sticky");
} else {
navigation.classList.remove("sticky");
}
}
Script 2:
mybutton = document.getElementById("tothetop");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 98 || document.documentElement.scrollTop > 98) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
I am unable to figure out why they do not seem to work harmoniously together.