zenscroll
zenscroll copied to clipboard
Nice to be able to query if an element is viewable
Here is the code I would like to simplify
const scrollerHeight = container.clientHeight
const scrollerY = scroller.getY()
const targetHegiht = target.clientHeight
const targetY = scroller.getTopOf(target)
if (targetY + targetHegiht > scrollerY + scrollerHeight || targetY < scrollerY) {
// the target is not fully within the vertical scroll bar
scroller.center(target, 1000)
} else {
scroller.intoView(target, 1000)
}
if (!scroller.isFullyInView(target)) {
scroller.center(target, 1000)
} else {
scroller.intoView(target, 1000)
}