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
No related branches found
No related tags found
1 merge request!8Resolve "Expose manual scrollTo*() methods to public API"
import * as Velocity from 'velocity-animate';
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', {
duration: 1200, // todo: different depending on offset from page top?
easing: EASE_IN_SKIP_OUT_EASING,
complete: () => window.location.hash = hashTarget.getHash(),
});
if (typeof hashTarget === 'string') {
hashTarget = HashTarget.fromString(hashTarget, document);
}
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.
Finish editing this message first!
Please register or to comment