/
web-fly-to.js
41 lines (36 loc) · 1.11 KB
/
web-fly-to.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Ember from "ember";
var RSVP = Ember.RSVP;
export default function webFlyTo(opts={}) {
if (!this.newElement) {
return RSVP.resolve();
} else if (!this.oldElement) {
this.newElement.css({visibility: ''});
return RSVP.resolve();
}
var oldOffset = this.oldElement.offset();
var newOffset = this.newElement.offset();
var initialState = {
transform: 'translateX(0px) translateY(0px)',
width: this.oldElement.width() + 'px',
height: this.oldElement.height() + 'px'
};
var finalState = {
transform: `translateX(${newOffset.left - oldOffset.left}px) translateY(${newOffset.top - oldOffset.top}px)`,
width: this.newElement.width(),
height: this.newElement.height()
};
return new RSVP.Promise((resolve) => {
this.newElement.css({ visibility: 'hidden' });
var animationRunner = this.oldElement[0].animate([
initialState,
finalState
], {
duration: opts.duration || 500,
});
animationRunner.onfinish = () => {
this.oldElement.css({ visibility: 'hidden' });
this.newElement.css({ visibility: ''});
resolve();
};
});
}