-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframeAnimation.js
39 lines (39 loc) · 1.04 KB
/
frameAnimation.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
(function(){
"use strict";
var i, image;
function imagePreloader(count, path, type){
var resultArray = [];
for(i = 1; i <= count; i++){
image = new Image();
image.src = path + i + "." + (type || "png");
resultArray.push(image);
}
return resultArray;
}
function FrameAnimation(element, options){
this.element = element;
Object.keys(options).forEach(function(option){
this[option] = options[option];
}, this);
this.counter = this.startIndex;
}
FrameAnimation.prototype.animate = function(){
var that = this;
this.animationInterval = setInterval(function(){
that.element.style.backgroundImage = "url('" + that.imagesArray[that.counter].src + "')";
that.counter++;
if(that.counter === that.count - 1){
that.stopAnimate();
if(that.repeat){
that.animate();
}
}
}, that.time);
};
FrameAnimation.prototype.stopAnimate = function(){
clearInterval(this.animationInterval);
this.counter = this.startIndex;
};
window.imagePreloader = imagePreloader;
window.FrameAnimation = FrameAnimation;
})();