how to create a counter or ticker showing numbers for websites in a slider

你离开我真会死。 提交于 2019-12-23 04:33:32

问题


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:


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
});


来源:https://stackoverflow.com/questions/17964596/how-to-create-a-counter-or-ticker-showing-numbers-for-websites-in-a-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!