use scrollIntoView which is more consistent than previous strategy

This commit is contained in:
Nolan Lawson 2018-03-29 23:01:36 -07:00
parent b4fc6cf99e
commit c54bde0a19
1 changed files with 6 additions and 15 deletions

View File

@ -75,24 +75,15 @@
}
},
methods: {
scrollToPosition(rect) {
scrollToPosition(element) {
if (this.get('scrolledToPosition')) {
return
}
this.set({scrolledToPosition: true})
console.log('scrollToPosition', rect.top)
let container = document.querySelector(this.get('containerQuery'))
if (!container) {
return
}
let containerRect = container.getBoundingClientRect()
let scrollTop = rect.top - containerRect.top
if (scrollTop !== 0) {
requestAnimationFrame(() => {
console.log('setting scrollTop to ', scrollTop)
container.scrollTop = scrollTop
console.log('scrolling element into view')
element.scrollIntoView(true)
})
}
},
onIntersection(entries) {
mark('onIntersection')
@ -107,7 +98,7 @@
height: rect.height
}
if (scrollToItem === key) {
this.scrollToPosition(rect)
this.scrollToPosition(entry.target)
}
}
intersectionStates = Object.assign(intersectionStates, newIntersectionStates)