As I work on creating a page that showcases various types of media predominantly consisting of images and videos, I have encountered a challenge. I am striving to prevent users from scrolling too far past the displayed media. My goal is to ensure that when a user scrolls down to view the next media object, once it reaches the center of the screen, the scrolling should briefly pause to avoid overshooting.
I attempted to implement a solution found at
However, it seems to function correctly only for the first div element...
Below is the code snippet:
.scroll-snappers,
.snapit {
height: fit-content;
}
.scroll-snappers {
scroll-snap-type: y mandatory;
}
.snapit {
scroll-snap-align: start;
}
<script src="https://rawgit.com/ckrack/scrollsnap-polyfill/develop/dist/scrollsnap-polyfill.bundled.js"></script>
<div class="scroll-snappers">
<div class="snapit">
<img src="https://i.imgur.com/iNku1gA.jpg" height="500" />
</div>
<div class="snapit">
<img src="https://i.imgur.com/iNku1gA.jpg" height="500" />
</div>
<div class="snapit">
<img src="https://i.imgur.com/iNku1gA.jpg" height="500" />
</div>
<div class="snapit">
<img src="https://i.imgur.com/iNku1gA.jpg" height="500" />
</div>
</div>