GithubHelp home page GithubHelp logo

gfcarvalho / image-manager.js Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 153 KB

ImageManager, a Javascript HTML5 Image library: Preload, cache and manage image assets.

Home Page: http://gh.gustavocarvalho.eti.br/image-manager.js/

License: MIT License

JavaScript 92.11% CSS 1.05% HTML 6.84%

image-manager.js's Introduction

Build Status Code Climate

By Gustavo Carvalho

ImageManager.js is an easy to use, small and standalone but powerful and complex library that gives you amazing control of your image assets by preloading, caching and managing it.

Get total control of the images on your page by using ImageManager.js.

##Features

  • Tag loading and eased progress information
  • Event oriented
  • After loaded, all images will be accessible through a cache object
  • Create independent load tasks

##Examples:

Preload a set of images, show the loading progress using the progress element and draw it on a canvas when load finishes. View Demo

var images = [{
    name: "bkg",
    src: "img/background.png"
}, {
    name: "frg",
    src: "img/foreground.png"
}, {
    name: "player",
    src: "img/player.png"
}];

var progressElem = document.getElementById('progress');
var canvasContext = document.getElementById('canvas').getContext('2d');

function onComplete(e) {
    var status = e.status; // OK : all images successfully downloaded,
                           // FAIL : one or more image has failed to download      
                           // ABORTED : one or more images weren't downloaded because user clicked on X button

    var cache = ImageManager.cache; // retrieve the cache

    if (status === ImageManager.OK) {
        // draw images on canvas
        canvasContext.drawImage(cache.bkg, 0, 0);
        canvasContext.drawImage(cache.frg, 0, 0);
        canvasContext.drawImage(cache.player, 60, 180);
    } else {
        // notify the user and ask to reload the page
        if(confirm('Error on load images. Reload the page to try again?')) {
            window.location.reload();
        }
    }
}

function onProgress(progress) {
    progressElem.value = progress;
    progressElem.innerHTML = 'Loading...' + progress + '%';
}

ImageManager.load(images, onComplete, onProgress); // start the loading process
    

View Demo

image-manager.js's People

Contributors

gfcarvalho avatar

Stargazers

Eric Kugel avatar  avatar

Watchers

 avatar

image-manager.js's Issues

Automated build

Add an automated build tool that optimizes and compresses the code.

Options:

  • Grunt (preferable)
  • Google Closure Compiler

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.