-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.js
More file actions
60 lines (56 loc) · 1.74 KB
/
Copy pathanimation.js
File metadata and controls
60 lines (56 loc) · 1.74 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class asciiAnimation {
constructor(folder,frameQuantity) {
this.folder = folder;
this.frameQuantity = frameQuantity;
this.textList =new Array(frameQuantity)
this.animationCheck = true;
this.test = ''
this.currentFrame = 0;
this.animationDelay = 200;
this.load()
}
load(){
var _this = this;
for(let i=0;i<this.frameQuantity;i++){
let stringCounter = i.toString();
while (3 > stringCounter.length){
stringCounter = '0'+stringCounter
}
let textFile = stringCounter+'.txt';
var xhr=new XMLHttpRequest;
console.log(i)
xhr.frameNumber = i
xhr.open('GET',this.folder+textFile);
xhr.onload = function(){_this.textList[this.frameNumber] = this.response}
xhr.send()
}
}
nextFrame(){
if(this.animationCheck){
let pre=document.getElementById('animation');
pre.innerHTML=this.textList[this.currentFrame];
this.currentFrame ++
if (this.currentFrame>=this.textList.length){
this.currentFrame = 0;
}
setTimeout(() => {this.nextFrame(); }, this.animationDelay);
}
}
pause(){
this.animationCheck=false;
let _this = this
//document.getElementById('pauseButton').value = 'Play'
//document.getElementById('pauseButton').onclick = function(){_this.play()}
}
play(){
this.animationCheck=true;
this.nextFrame()
//document.getElementById('pauseButton').value = 'Pause'
let _this = this
//document.getElementById('pauseButton').onclick = function(){_this.pause()};
}
}
var flag
function load(){
flag = new asciiAnimation('flag/', 15);
}