Skip to content
Snippets Groups Projects
Commit e0b93aaa authored by Daniel Kurowski's avatar Daniel Kurowski
Browse files

ScrollToTarget: take advantage of scrollToElement()

parent 253a70f9
Branches
Tags
1 merge request!8Resolve "Expose manual scrollTo*() methods to public API"
import * as Velocity from 'velocity-animate';
import {HashTarget} from '../HashTarget'; import {HashTarget} from '../HashTarget';
import {EASE_IN_SKIP_OUT_EASING} from '../easing/setupVelocity'; import {scrollToElement} from './scrollToElement';
import {assert} from '../assert';
export function scrollToTarget(hashTarget: HashTarget): void export function scrollToTarget(hashTarget: HashTarget|string, onScrollFinishedCallback?: () => void): void
{ {
Velocity.animate(hashTarget.getElement(), 'scroll', { if (typeof hashTarget === 'string') {
duration: 1200, // todo: different depending on offset from page top? hashTarget = HashTarget.fromString(hashTarget, document);
easing: EASE_IN_SKIP_OUT_EASING, }
complete: () => window.location.hash = hashTarget.getHash(),
}); scrollToElement(
hashTarget.getElement(),
() => {
assert(hashTarget instanceof HashTarget);
window.location.hash = hashTarget.getHash();
onScrollFinishedCallback !== undefined && onScrollFinishedCallback();
},
);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment