GithubHelp home page GithubHelp logo

preload's Introduction

Preload

介绍

原生 JavaScript 实现的预加载库,兼容到 IE7+。

效果演示:https://mqyqingfeng.github.io/Preload/

兼容性

IE7+

依赖

原生 JavaScript 实现,无依赖。

大小

压缩后 2KB,gzip 压缩后更小。

下载

git clone git@github.com:mqyqingfeng/Preload.git

使用

<script src="path/preload.js"></script>

或者

import Preload from 'path/preload.js'

示例

var pics = [
    "https://mqyqingfeng.github.io/demo/img/yayu.jpeg",
    ...
]

new Preload(pics, {
    progress: function(index, total, type){
        var percent = Math.floor(index / total * 100) + '%';
        console.log(percent);
    },
    complete: function(sucessNum, failNum){
        console.log('成功加载' + sucessNum + '张图片,加载失败' + failNum + '张图片');
    }
});

API

初始化

new Preload(options);

options

1.progress

当加载完一张图片时就会触发该函数

new Preload(pics, {
    // 函数有 3 个参数
    // index 表示加载到第几张图片
    // totoal 表示一共需要记载几张图片
    // type 加载的类型,成功还是失败,成功为 'success',失败为 'fail'
    progress: function(index, total, type){
        var percent = Math.floor(index / total * 100) + '%';
        console.log(percent);
    }
});

2.complete

当所有图片加载完毕时触发

new Preload(pics, {
    // 函数有 2 个参数
    // sucessNum 表示成功加载的个数
    // failNum 表示加载失败的个数
    complete: function(sucessNum, failNum){
        console.log('成功加载' + sucessNum + '张图片,加载失败' + failNum + '张图片');
    }
});

preload's People

Contributors

mqyqingfeng avatar

Watchers

James Cloos avatar Seeker 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.