npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

browser-simple-loader

v1.1.1

Published

Simple html5 (based on svg) loader in browser

Downloads

324

Readme

browser-simple-loader

browser-simple-loader - it's a simple html5 (based on svg) loader in browser.

Example

Install

npm install browser-simple-loader --save

Use (recommended)

Create your es6 file:

// my-file.js

'use strict';

import Loader from 'browser-simple-loader';

class Test {
    constructor() {
        let loader = new Loader();

        loader.show();
    }
}

export default new Test();

and then build it with webpack.

Add to html page you generated script and open your page:

<script src='my-bundle.js'></script>

You will see a Loader.

Use in html (without build)

Of course you can just include on page compiled file and use it.

  • download browser-simple-loader.js from /build/ folder from project page
  • added script tag with browser-simple-loader.js on your page
<script src="/path-to/browser-simple-loader.js"></script>

<script>	
    var loader = new window.Loader(); // window.Loader is a global object if you choose this method.
    
    loader.show();
</script>

API

constructor()

import Loader from 'browser-simple-loader';
let loader = new Loader({...});

or just call in browser (if you choose 'Use in html (without build)')

let loader = new window.Loader({...});

default configuration is:

{            
    size: 120, // px
 
    duration: 1, // seconds
    radius: 8, // px
    colors: [
        ['#c5523f', '#f2b736'],
        ['#f2b736', '#499255'],
        ['#499255', '#1875e5'],
        ['#1875e5', '#c5523f'],
    ],
 
    templates: {
        style: null, // <style>....</style>
        loader: null // <svg>....</svg>
    },
 
    container: document.getElementsByTagName('body')[0], // DOM element
 
    className: 'browser-simple-loader' // String
}

Default templates is:

templates.style

<style type="text/css">
    .browser-simple-loader {
        background: rgba(255, 255, 255, 0.5);
        bottom: 0;
        left: 0;
        position: fixed;
        right: 0;
        top: 0;
        z-index: 1000;
        display: none;
    }

    .browser-simple-loader svg {
        position: fixed;
        left: 50%;
        top: 50%;
        z-index: 1001;
        margin: -${size / 2}px 0 0 -${size / 2}px;
    }
</style>

templates.loader

<svg width="${size}px" height="${size}px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
    <rect x="0" y="0" width="100" height="100" fill="none"></rect>
    <g transform="rotate(0 50 50)">
        <circle r="${radius}" cx="20" cy="50" transform="translate(23.4991 -23.4991)">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="${duration}s" values="0 0;30 -30" keyTimes="0;1"></animateTransform>
            <animate attributeName="fill" dur="${duration}s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="${colors[0][0]};${colors[0][1]}"></animate>
        </circle>
    </g>
    <g transform="rotate(90 50 50)">
        <circle r="${radius}" cx="20" cy="50" transform="translate(23.4991 -23.4991)">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="${duration}s" values="0 0;30 -30" keyTimes="0;1"></animateTransform>
            <animate attributeName="fill" dur="${duration}s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="${colors[1][0]};${colors[1][1]}"></animate>
        </circle>
    </g>
    <g transform="rotate(180 50 50)">
        <circle r="${radius}" cx="20" cy="50" transform="translate(23.4991 -23.4991)">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="${duration}s" values="0 0;30 -30" keyTimes="0;1"></animateTransform>
            <animate attributeName="fill" dur="${duration}s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="${colors[2][0]};${colors[2][1]}"></animate>
        </circle>
    </g>
    <g transform="rotate(270 50 50)">
        <circle r="${radius}" cx="20" cy="50" transform="translate(23.4991 -23.4991)">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="${duration}s" values="0 0;30 -30" keyTimes="0;1"></animateTransform>
            <animate attributeName="fill" dur="${duration}s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="${colors[3][0]};${colors[3][1]}"></animate>
        </circle>
    </g>
</svg>

Create loader with own config:

let loader = new Loader({
    size: 400,
    duration: 0.8,
    radius: 10,
    container: document.getElementById('my-loader-container')
});

loader.show();

show()

Method to show Loader.

loader.show();

hide()

Method to hide Loader.

loader.hide();

static getInstance()

Static method to get instance of Loader.

import Loader from 'browser-simple-loader';

...
let loader = new Loader({...});
...

Loader.getInstance(); // return result of the first new Loader();