mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
2d6f48093e
no issue - `when` makes the modifier a little easier to read for it's typical use-case, eg: - `{{scroll-to when=(eq entry.slug this.entry)}}` - `{{scroll-to when=(eq this.focusArea "analytics")}}`
14 lines
518 B
JavaScript
14 lines
518 B
JavaScript
import getScrollParent from 'ghost-admin/utils/get-scroll-parent';
|
|
import {modifier} from 'ember-modifier';
|
|
|
|
export default modifier((element, positional, {when = true}) => {
|
|
if (when) {
|
|
// setTimeout needed to ensure layout has finished and we have accurate positioning
|
|
setTimeout(() => {
|
|
const scrollParent = getScrollParent(element);
|
|
const y = element.offsetTop;
|
|
scrollParent.scrollTo({top: y, behavior: 'smooth'});
|
|
}, 200);
|
|
}
|
|
}, {eager: false});
|