-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmover.js
More file actions
41 lines (39 loc) · 1.12 KB
/
mover.js
File metadata and controls
41 lines (39 loc) · 1.12 KB
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
AFRAME.registerComponent('mover', {
init: function() {
let el = this.el;
this.animateMove = function() {
let currPosition = el.getAttribute('position');
let params = {
property: 'position',
to: {
x: currPosition.x - 5,
y: currPosition.y,
z: currPosition.z
},
dur: 5000,
easing: 'easeInOutElastic'
};
el.setAttribute('animation', params);
}
this.returnMove = function(e) {
let p = e.detail.returnPoint;
let params = {
property: 'position',
to: {
x: p.x,
y: p.y + 2,
z: p.z
},
dur: 5000,
easing: 'easeInOutQuad'
};
el.setAttribute('animation', params);
}
this.el.addEventListener('click',this.animateMove);
this.el.sceneEl.addEventListener('returnSphere', this.returnMove);
},
remove: function() {
this.el.removeEventListener('click', this.animateMove);
this.el.sceneEl.removeEventListener('returnSphere', this.returnMove);
}
});