Answer the question
In order to leave comments, you need to log in
How to fix a block after passing a certain part of the page in javascript??
Hello, you need to fix the div block, but only after the user has scrolled a certain part of the page!
For example, in the header part there is no block that needs to be fixed,
it is in the content part,
and when scrolling through the entire content, it must be fixed, and when raised to the header area, it remains in the content
Answer the question
In order to leave comments, you need to log in
If I understand correctly what you need, then I cannot but say that one hundred thousand two hundred and three times this topic has been discussed.
document.addEventListener("scroll", function(){
var elem = document.querySelector("header");
document.querySelector("#block").classList[elem.getBoundingClientRect().top < elem.offsetHeight ? "add" : "remove"]("visible");
//Когда header не видим, элементу #block присваивается класс visible
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question