I want to add class activeclass
to a particular outerbox
div element when scroll reaches to it. and I also want to remove that class from it and assign it to the next outerbox
when scroll reach to that div.
Below is the sample HTML code. and I want you guys to suggest me the jQuery for this.
<div class="outerbox">
<div class="innerbox">
content goes here
</div>
</div>
<div class="outerbox">
<div class="innerbox">
content goes here
</div>
</div>
<div class="outerbox">
<div class="innerbox">
content goes here
</div>
</div>
<div class="outerbox">
<div class="innerbox">
content goes here
</div>
</div>
<div class="outerbox">
<div class="innerbox">
content goes here
</div>
</div>
I want you to please suggest me jQuery code to add & remove CSS class from one to other outerbox div
3
Answers
You could try this sample snippet below and customize as needed.
You could use
document.elementFromPoint()
to set the active class for an element is a particular position in the window on scrolling:Don’t use the
"scroll"
event,use the preferred tool for the task, and that’s the IntersectionObserver API
Style the
.outerbox.is-inViewport {
CSS class for the desired changes