Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make a window stick?

I have some divs that are 100VH and I’m trying to make it where when I scroll just once it will lock on to the next div. EXAMPLE: https://olaolu.dev/ (when you just touch the scroll wheel once it locks on to another part of the page)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The effect you’re referring to is called snap scrolling or scroll snapping. It allows a scrollable container to stop at certain points (in your case, at the next div) after scrolling. You can achieve this with CSS scroll snapping.

Here’s an example implementation:

HTML

<div class="scroll-container">
  <div class="scroll-item">
    <!-- content of first div -->
  </div>
  <div class="scroll-item">
    <!-- content of second div -->
  </div>
  <div class="scroll-item">
    <!-- content of third div -->
  </div>
  <!-- add more scroll items as needed -->
</div>

CSS

.scroll-container {
  scroll-snap-type: y mandatory;
  overflow-y: scroll;
  height: 100vh;
}

.scroll-item {
  scroll-snap-align: start;
  height: 100vh;
}

This will make it so that the container will snap to the next item when you scroll, assuming the container is 100vh tall. The scroll-snap-type: y mandatory; property specifies the container should scroll vertically, and scroll-snap-align: start; specifies the container should snap to the top of each item.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading