Coder Social home page Coder Social logo

elf-preloader.js's Introduction

preloader.js NPM version

中文说明

A simple Javascript library for preload image and audio. The main feature:

  • set concurrency
  • set minimum loading time per resouce, for simulate slow load

Install

npm install --save preloader.js

Usage

Import

var Preloader = require('preloader.js')

Execute

var preloader = new Preloader({
    resources: ['assert/images/logo.png', 'assert/audios/bg.mp3'],
    concurrency: 4
})
preloader.addProgressListener(function (loaded, length) {
    console.log('loading ', loaded, length, loaded / length)
})
preloader.addCompletionListener(function () {
    console.log('load completed')
})
preloader.start()

PS: If no use module bundler (e.g.: webpack、browserify), you can direct reference

<script src="src/preloader.js"></script>

Introduce

configuration

  • resources Array

    Default: [].

    Preload resouce list. The files of postfix belong to ['mp3', 'ogg', 'wav'] to according audio handle.

    PS:Resources in addition to here configuration, including configured attr value DOM node.

  • concurrency Number

    Default: 0.

    Concurrent number. 0 is no concurrency limit.

  • perMinTime Number

    Default: 0. Unit: ms

    Minimum loading time per resouce. Usually used to simulate load slow.

  • attr String

    Default: data-preload.

    DOM node attribute. Example: <img src="img/logo.png" data-preload/>, the 'img/logo.png' will been added in resources.

  • onProgress Function

    Default: null.

    Every resouce load is completed the callback function. The effect same to addProgressListener.

  • onCompletion Function

    Default: null.

    All resouces load is completed the callback function. The effect same to addCompletionListener.

instance method

addProgressListener(Function)

Set every resouce load is completed the callback function

addCompletionListener(Function)

Set all resouces load is completed the callback function

get(String)

Get instances of completed

start()

Begin load. All ready after invoke.

License

MIT

elf-preloader.js's People

Contributors

booxood avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.