UNPKG

649 BPlain TextView Raw
1import { TweenMax } from 'gsap';
2import * as log from 'loglevel';
3
4
5// Get the boundingbox of respective elements, calculate
6// the diff and animate to the same values
7function warp(elementToMove: Element, targetElement: Element): void {
8 const box = targetElement.getBoundingClientRect();
9 const targetLeft = box.left;
10
11 log.debug("targetLeft is %o", targetLeft);
12
13
14 const sourceLeft = elementToMove.getBoundingClientRect().left;
15 log.debug("sourceLeft is %o", sourceLeft);
16
17 const diff = sourceLeft - targetLeft;
18
19 log.debug("will move %o", diff);
20
21 TweenMax.to(elementToMove, 1, { x: -diff });
22}
23
24export default { warp };