<script>
function Tom(){
this.imgShow = document.getElementById('imgShow');
this.btn = document.querySelectorAll('div');
this.music = document.getElementById('music');
this.init();
}
Tom.prototype = {
init : function(){
this.eventBind();
},
tomPlay : function(name,num){
var _this = this;
this.count = 0 ;
clearInterval(this.timer);
this.timer = setInterval(function(){
if(_this.count >= num){
clearInterval(_this.timer);
_this.count = 0 ;
}else{
_this.count++;
_this.imgShow.src = './tom/img/Animations/'+name+'/'+name+'_' + _this.mendZero(_this.count)+'.jpg';
}
},80)
},
mendZero : function(num){
if(num < 10){
return '0' + num;
}else{
return num;
}
},
eventBind : function(){
var _this = this;
for(let i = 0 , k = this.btn.length ; i < k ; i++){
this.btn[i].onclick = function(){
let classN = this.className;
switch(classN){
case 'cymbal' :
_this.tomPlay('cymbal',12);
_this.music.src = './tom/mp3/pia.mp3';
_this.music.play();
break;
case 'drink' :
_this.tomPlay('drink',80);
break;
case 'eat' :
_this.tomPlay('eat',39);
break;
case 'fart' :
_this.tomPlay('fart',27);
break;
case 'pie' :
_this.tomPlay('pie',23);
break;
case 'scratch' :
_this.tomPlay('scratch',55);
break;
case 'angry' :
_this.tomPlay('angry',25);
break;
case 'angry1' :
_this.tomPlay('angry',25);
break;
case 'footLeft' :
_this.tomPlay('footRight',29);
_this.music.src = './tom/mp3/tomaiyou.mp3';
_this.music.play();
break;
case 'footRight' :
_this.tomPlay('footLeft',29);
_this.music.src = './tom/mp3/tomaiyou.mp3';
_this.music.play();
break;
case 'knockout' :
_this.tomPlay('knockout',80);
break;
case 'stomach' :
_this.tomPlay('stomach',33);
_this.music.src = './tom/mp3/tomaiyou.mp3';
_this.music.play();
break;
}
}
}
}
}
new Tom();
</script>