Firefox 39, Safari 9 and IE11 provide support for CSS Scroll Snap Points. Chrome has the feature in development.
Is there a polyfill that would emulate the following
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
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.
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
import ScrollSnap from 'scroll-snap'
const snapConfig = {
scrollSnapDestination: '90% 0%', // scroll-snap-destination css property, as defined here: https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-destination
scrollTimeout: 100, // time in ms after which scrolling is considered finished
scrollTime: 300 // time in ms for the smooth snap
}
function callback () {
console.log('called when snap animation ends')
}
const element = document.getElementById('container')
const snapObject = new ScrollSnap(element, snapConfig)
snapObject.bind(callback)
// unbind the element
// snapObject.unbind();