I wanted to creat a script to change my website's link for 4 others compartments. I tried to creat that this way. Is it possiable? If able what should I change? I gave document.getElementById("p1").innerHTML = "x!"; just for testing to see effects of my fuction, but that still doesn't work.
<script>
window.onscroll = function() {testscrollFunction()};
function testscrollFunction() {
var scrollPosition = document.body.scrollTop || document.documentElement.scrollTop;
if (scrollPosition >= 0 && scrollPosition <= 400)
{
history.pushState({}, null, "index.html#1");
document.getElementById("p1").innerHTML = "1!";
}
if (scrollPosition >= 401 && scrollPosition <= 600)
{
history.pushState({}, null, "index.html#2");
document.getElementById("p1").innerHTML = "2!";
}
if (scrollPosition >= 601 && scrollPosition <= 800)
{
history.pushState({}, null, "index.html#3");
document.getElementById("p1").innerHTML = "3!";
}
}
</script>
Same way I have done other script (for button which can scroll to top and shows at height higher than 40) and it works. Can't I have 2 times window.onscroll functions?
Aucun commentaire:
Enregistrer un commentaire