Answer the question
In order to leave comments, you need to log in
How to change url when scrolling by blocks?
Plz tell me how to change the url when scrolling. For example, initially the url is: sait.name , scroll to the second block, the url changes to: sait.name/ ?page2 , scroll to the third block, the url changes to: sait.name/ ?page3 In the opposite direction, it changes accordingly.
The hash solution is not suitable.
Help, at least in which direction to dig?
Answer the question
In order to leave comments, you need to log in
Example of pushState() method
Only possible for HTML5. The history is saved, the back button takes you to the previous block !!!
window.onscroll = function() {
let scrolled = window.pageYOffset || document.documentElement.scrollTop;
let block = "page";
if (scrolled>99 & scrolled<200) {
block = "page1";
} else if (scrolled>=200 & scrolled<400) {
block = "page2";
} else if (scrolled>=400) {
block = "page3";
}
history.pushState({}, "", block);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question