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
| (function () { this.count = 0; this.eventList = {}; this.on = function (type, listener) { if (typeof this.eventList[type] == "undefined") { this.eventList[type] = listener; } }; setInterval(function () { if (this.count == 100) { if(this.eventList.end instanceof Function){ this.eventList.end(); } this.count = 0; } else if (this.count == 0) { if(this.eventList.start instanceof Function){ this.eventList.start(); } this.count++; } else { if(this.eventList.tick instanceof Function){ this.eventList.tick(); } this.count++; } }.bind(this), 50) t = this; })()
t.on("start", function () { document.getElementById('states').innerHTML = 'start'; document.getElementById('value').innerHTML = t.count; }) t.on("tick", function () { document.getElementById('states').innerHTML = 'tick'; document.getElementById('value').innerHTML = t.count; }) t.on("end", function () { document.getElementById('states').innerHTML = 'end'; document.getElementById('value').innerHTML = t.count; })
|