提交 b3024827 编写于 作者: K Kamran Ahmed

Add scrollIntoView option

上级 8f33536b
......@@ -79,12 +79,21 @@ export default class Element {
return;
}
const scrollIntoViewOptions = this.options.scrollIntoViewOptions || {
behavior: 'smooth',
block: 'center',
};
this.node.scrollIntoView(scrollIntoViewOptions);
// If browser supports scrollIntoView, use that otherwise center it manually
if (this.node.scrollIntoView) {
const scrollIntoViewOptions = this.options.scrollIntoViewOptions || {
behavior: 'smooth',
block: 'center',
};
this.node.scrollIntoView(scrollIntoViewOptions);
} else {
const elementRect = this.node.getBoundingClientRect();
const absoluteElementTop = elementRect.top + this.window.pageYOffset;
const middle = absoluteElementTop - (this.window.innerHeight / 2);
this.window.scrollTo(0, middle);
}
}
/**
......
......@@ -27,6 +27,7 @@ export default class Driver {
animate: OVERLAY_ANIMATE, // Whether to animate or not
opacity: OVERLAY_OPACITY, // Overlay opacity
padding: OVERLAY_PADDING, // Spacing around the element from the overlay
scrollIntoViewOptions: null, // Options to be passed to `scrollIntoView`
onHighlightStarted: () => { // When element is about to be highlighted
},
onHighlighted: () => { // When element has been highlighted
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册