how to create a counter or ticker showing numbers

2019-06-10 06:24发布

How or where can i get a counter something similar to this? I am aware of the sliders but the counter in the slider is something i am looking for and developing the website with HTML5, jquery.

1条回答
虎瘦雄心在
2楼-- · 2019-06-10 07:16

I'm not sure I got the question 100%, anyway, here's my attempt:

JSFiddle

var Counter = function(options) {
    var start = options.start;
    this.init = function() {
        var self = this;
        var t = window.setInterval(function() {
            start+=1;
            self.render(start);
         }, options.interval)
    }

    this.render = function(number) {
    var stringVal = number.toString();
        var arr = stringVal.split('');
        for(var i = 0; i < arr.length ; i++) {
            $('.number').eq(i).text(arr[i]);
        }
    }

    this.init();
}
var counter = new Counter({
    start: 123456777,
    interval: 1000 //milliseconds
});
查看更多
登录 后发表回答