-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVtron.AnimatedObject.js
68 lines (50 loc) · 1.44 KB
/
Vtron.AnimatedObject.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
if(!Vtron){ var Vtron = {}; }
(function (Vtron) {
Vtron.AnimatedObject = new Class({
//-------------------------------------------------
initialize: function(element,x,y) {
this.element = element;
this.element.setStyles({
position:'absolute',
left:'0px',
top:'0px'
});
this.pos = {
x:0,
y:0
}
this.setPos(0,0); //Enable hardware accelleration
this.scale = 1.0;
this.rotation = 0;
this.interval = 0;
},
//-------------------------------------------------
update: function(bAnimate,time) {
var transitionTime = 0.5;
if(time) transitionTime = time;
//Set Transition
if(bAnimate) {
this.element.setStyle('-webkit-transition','all ' + transitionTime + 's ease-out');
} else {
this.element.setStyle('-webkit-transition', '-webkit-transform 0.0s');
}
//Set Position
var translation = 'translate3d(' + this.pos.x + 'px,' + this.pos.y + 'px,0px)';
//Set Rotation
var rotation = 'rotate3d(0,0,1,' + this.rotation + 'deg)';
//Set Scale
var scale = 'scale(' + this.scale + ')';
this.element.setStyle('-webkit-transform',translation + ' ' + rotation + ' ' + scale);
},
//-------------------------------------------------
setPos: function(x,y,bAnimate, time) {
this.pos.x = x;
this.pos.y = y;
if(time) {
this.update(bAnimate, time);
} else {
this.update(bAnimate);
}
}
})
})(Vtron);