Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Создание счеткика (https://javascript.ru/forum/dom-window/57571-sozdanie-schetkika.html)

Shketkol 09.08.2015 20:25

Создание счеткика
 
Здравствуйте, нужно создать счетчик. Только числа должны увеличатся от 0 до максимального числа, которое указаное

Lemme 09.08.2015 22:03

Счетчик чего?

javaQest 09.08.2015 22:37

Counter={
 create: function(max){
   var o=Object.create(this)
   o.max=max
   return o
 },
 value: 0,
 step: function(){
  with(this) with(console){
   if(value>=max) return log("done")
   log(++value)
  }
 }
}


with(Counter.create(3)) step(), step(), step(), step()
with(Counter.create(5)) step(), step(), step(), step(), step(), step()

javaQest 09.08.2015 23:16

либо так
createCounter=function(max){
 var value=0
 return function(){
   with(console){
   if(value>=max) return log("done")
   log(++value)
  }
 }
}

counter=createCounter(3)

counter()
counter()
counter()
counter()

counter=createCounter(5)

counter()
counter()
counter()
counter()
counter()
counter()

Vlasenko Fedor 09.08.2015 23:34

var myCounter = {
    max: 0,
    position: 0,
    get cur() {
        if (this.position == this.max) this.position = 0;
        this.position += 1;
        return this.position;
    },
    set cur(arg) {
        this.max = arg;
    }
};
myCounter.cur = 3;
console.log(myCounter.cur);
console.log(myCounter.cur);
console.log(myCounter.cur);
console.log(myCounter.cur);


function next(max) {
    var i = 0;
    return function () {
        i = i < max ? i + 1 : 1;
        return i;
    };
}
var current = next(3);
console.log(current());
console.log(current());
console.log(current());
console.log(current());

Shketkol 11.08.2015 18:00

Вложений: 1
Как на сайте
http://www.codefire.com.ua/

рони 11.08.2015 18:45

Shketkol,
http://aishek.github.io/jquery-animateNumber/

Shketkol 12.08.2015 15:42

А как с ним работать. Например с первым. Код разметки добавил в html, в файл js скинул код с lines, но анимации нету


Часовой пояс GMT +3, время: 23:16.