/
animated-item.js
53 lines (37 loc) · 1.34 KB
/
animated-item.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
42
43
44
45
46
47
48
49
50
51
52
53
import Component from '@ember/component';
import Mixin from '@ember/object/mixin';
import { assert } from '@ember/debug';
import layout from 'ember-scrollmagic/templates/components/base-item';
import {
default as EmberObject,
computed,
get
} from '@ember/object';
import ScrollMagic from 'scrollmagic';
import { TimelineMax, TweenLite } from 'gsap';
import defaultAnimations from 'ember-scrollmagic/utils/animations';
import ScrollMagicSceneMixin from 'ember-scrollmagic/mixins/components/scene-mixin';
export const ScrollMagicAnimatedMixin = Mixin.create(
ScrollMagicSceneMixin, {
layout,
setupScene() {
let opts = get(this, 'mergedOptions'),
timeline = get(this, 'timeline');
return new ScrollMagic.Scene(opts).setTween(timeline)
},
animation: computed(function() {
assert(`Please define an animation type for ScrollMagic animated component`);
}),
animations: computed(function() {
return EmberObject.create(defaultAnimations);
}),
timeline: computed('animation', function() {
let name = get(this, 'animation'),
animation = get(this, `animations.${name}`);
assert(`ScrollMagic animation '${name}' does not exist.`, animation);
return new TimelineMax().add(
TweenLite.fromTo(this.element, 1, ...animation)
);
})
});
export default Component.extend(ScrollMagicAnimatedMixin);