Hi to everyone
I'm a beginner so sorry for my gaps.
I'm trying to figure out how trigger two different elements (in these example, just to simplify, are equals in size and movement) on scrolling.
When I try to load these two specifics function just one works. Is there any conflict?
FIRST FUNCTION
menuToFixed = hypeDocument.getElementById('circle');
window.onscroll = function() {
if (scrollY < 23) {
menuToFixed.style.position = "absolute";
menuToFixed.style.top = "23px";
menuToFixed.style.left = "fixed";
menuToFixed.style.right = "fixed";
} else if (scrollY > 23 && scrollY < 250) {
menuToFixed.style.position = "fixed";
menuToFixed.style.top = "0px";
menuToFixed.style.left = "fixed";
menuToFixed.style.right = "fixed";
} else if (scrollY > 250){
menuToFixed.style.position = "absolute";
menuToFixed.style.top = "250";
menuToFixed.style.left = "fixed";
menuToFixed.style.right = "fixed";
}
}
test.zip (22.7 KB)
SECOND FUNCTION
menu = hypeDocument.getElementById('circle2');
window.onscroll = function() {
if (scrollY < 23) {
menu.style.position = "absolute";
menu.style.top = "23px";
menu.style.left = "fixed";
menu.style.right = "fixed";
} else if (scrollY > 23 && scrollY < 250) {
menu.style.position = "fixed";
menu.style.top = "0px";
menu.style.left = "fixed";
menu.style.right = "fixed";
} else if (scrollY > 250){
menu.style.position = "absolute";
menu.style.top = "250";
menu.style.left = "fixed";
menu.style.right = "fixed";
}
}
- Can I merge these two JavaScript in one to trigger two elements using hypeDocument.getElementById instead using classes?
Thanks in advance.