javascript - How to make multiple counters using HTML data -
i trying create similar this: http://pennystocks.la/internet-in-real-time/
here there at: https://jsfiddle.net/t44qsb9d/
jquery('document').ready(function() { var count = 0; var counter = document.queryselector('#foo'); var countnum = parseint(counter.dataset.counter,10); setinterval(function() { count += countnum; jquery('#foo').html(count); }, 1000); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <div style="background-color:#359bed;color:#ffffff;font-size:30px;padding:40px;"><div style="padding-left:300px;"><div id="foo" data-counter="11">0</div><span style="color:#ffffff;line-height:40px;">accounts created</span> </div> </div>
i need update script update multiple counters work on single counter. appreciated.
thanks, lewis
this counter object, can create many counter want:
function mycounter(startnum, increase, interval, selector){ this.countervalue = startnum; this.container = jquery(selector); this.paused = false; this.increase = increase; this.interval = interval; return this; } mycounter.prototype.start = function(){ var self = this; self.counter = setinterval(function(){ if(!self.paused){ self.countervalue += self.increase; if(self.container && self.container.html){ self.container.html(self.countervalue); } } }, self.interval); } mycounter.prototype.pause = function(){ this.paused = true; } mycounter.prototype.resume = function(){ this.paused = false; } mycounter.prototype.stop = function(){ clearinterval(this.counter); }
to use it:
var foocounter = new mycounter(0, parseint(counter.dataset.counter,10), 1000, '#foo') foocounter.start();
to pause , resume it:
foocounter.pause(); foocounter.resume();
to stop it:
foocounter.stop();
Comments
Post a Comment