How to emulate CSS Scroll Snap Points in Chrome?

I found a polyfill: https://github.com/zigotica/scrollSnapPointsPolyfill

Haven't tested it extensively.


If you're willing to consider a vanilla javascript re-implementation of this feature with a consistent cross browser behaviour you can use this library

Why

The main reason to use this instead of the native css solution is that it works in all modern browsers and has a customizable configuration to allow custom timing in transitions and scrolling detection.

How

The library re-implements the css snapping feature using vanilla javascript easing functions, and works using the values of the container element's scrollTop/scrollLeft properties and the scroll Event Listener

Example

import createScrollSnap from 'scroll-snap'

const element = document.getElementById('container')

const { bind, unbind } = createScrollSnap(element, {
  snapDestinationX: '0%',
  snapDestinationY: '90%',
  timeout: 100,
  duration: 300,
  threshold: 0.2,
  snapStop: false,
  easing: easeInOutQuad,
}, () => console.log('snapped'))

// remove the listener 
// unbind();

// re-instantiate the listener 
// bind();

Tags:

Css

Polyfills