forked from devops001/samsara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimations.js
50 lines (44 loc) · 1.17 KB
/
animations.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
var Animations = {
init: function() {
this.canvas = document.getElementById('canvas');
this.context = canvas.getContext('2d');
},
startAnimating: function(animation, image) {
Animations.stopAnimating();
var animationArgs = [image];
function animate() {
window.currentFrame = window.requestAnimationFrame(animate);
animation.apply(null, animationArgs);
}
animate();
},
stopAnimating: function() {
window.cancelAnimationFrame(window.currentFrame);
},
bounceZoom: function(image) {
if (!image.maxFrames) {
image.maxFrames = 10000;
image.atFrame = 1;
image.scaleRate = 0.00004;
image.scaleDir = 1;
image.scale = 1.0;
}
if (image.scaleDir > 0) {
if (image.atFrame < image.maxFrames) {
image.atFrame++;
image.scale = 1.0 + image.scaleRate;
} else {
image.scaleDir *= -1;
}
} else {
if (image.atFrame > 0) {
image.atFrame--;
image.scale = 1.0 - image.scaleRate;
} else {
image.scaleDir *= -1;
}
}
Animations.context.scale(image.scale,image.scale);
Animations.context.drawImage(image,0,0);
}
};