0.1.1 • Published 8 years ago

meta-countup v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

meta-countup.js

進捗とカウントアップ

Usage

再帰的なカウンター

const countup = require('meta-countup');
const COUNTER = 0;
const mc = countup(10);

tick(COUNTER);

function tick(count) {
  mc.step(count, (end, prog) => {

    console.log(prog + '%');

    if (end) {
      console.log('[End]');
    } else {
      return tick(++count);
    }
  });
}

画像の読み込みカウンター

var url = [ url1, url2, url3 ];
var mc = countup(url.length); // <-

for (var i = 0; i < url.length; i++) {
  imgOnLoad(new Image(), url[i], i);
}

function imgOnLoad(img, src, index) {
  img.onload = function() {
    mc.step(index, function(end, prog) { // <-
      console.log(prog + '% : ' + end + ' ' + src);
      if (end) console.log('読み込み完了');
    });
  };
  img.src = src;
}