Scroll Sync
Scroll synchronization (scroll-sync
), which associates multiple elements with scroll properties (overflow: scroll
). When a scroll event occurs in one of the elements, the scroll effect is mapped to all the elements associated with it. To achieve synchronization purposes. scroll-sync
supports fixed synchronization (px
) and relative synchronization (%
).
Acknowledgements
This is a rewrite of scroll-sync
with typescript
and added some new features liking scroll-sync only by x or y.
INSTALL
npm install @171h/scroll-sync
USAGE
import ScrollSync from 'scroll-sync'
const ss = new ScrollSync({
disabled: false,
relative: true,
doms: document.querySelectorAll('.scroll-container')
})
ss.set(document.querySelectorAll('.scroll-container'))
API
.add()
// add elements to scroll-sync.
ss.add(document.documentElement)
ss.add(document.querySelectorAll('.other-scroll-container'))
.remove()
// remove elements to scroll-sync.
ss.remove(document.documentElement)
ss.remove(document.querySelectorAll('.other-scroll-container'))
.set()
// reset elements to scroll-sync.
ss.set(document.documentElement)
ss.set(document.querySelectorAll('.other-scroll-container'))
.clear()
// reset elements to scroll-sync.
ss.clear()
DOCUMENT
Please click here for an online experience. (中文)