-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.js
61 lines (55 loc) · 1.43 KB
/
animation.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
const start = 36;
const end = 93;
const step = 4;
const stepQuantity = Math.floor((end-start)/step);
var textList =new Array(stepQuantity)
var animationCheck = true;
var newNumber = 0;
const animationFolder = 'demo/';
const msBetweenFrames = 200;
var loadCounter = 0;
function load(){
for(let i=0;i<stepQuantity;i++){
console.log('i '+i)
currentFrame = (start+i*step)
let stringCounter = currentFrame.toString();
while (3 > stringCounter.length){
stringCounter = '0'+stringCounter
}
textFile = stringCounter+'.txt';
var xhr=new XMLHttpRequest;
xhr.open('GET',animationFolder+textFile);
xhr.frameNumber = i
xhr.onload = addTxt
xhr.send()
}
}
function addTxt(){
textList[this.frameNumber]=(this.response);
loadCounter +=1
if (loadCounter == stepQuantity) {
playFrame(newNumber)
}
}
function playFrame(i){
if(animationCheck){
var pre=document.getElementById('animation');
pre.innerHTML=textList[i];
newNum = i+1
if (newNum>=textList.length){
newNum = 0;
}
setTimeout(() => { playFrame(newNum); }, msBetweenFrames);
}
}
function animationPause(){
if(animationCheck){
animationCheck=false;
document.getElementById('pauseButton').value = 'Play'
}
else{
animationCheck=true;
playFrame(newNumber)
document.getElementById('pauseButton').value = 'Pause'
}
}