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

favloader

v0.4.4

Published

Favicon Vanilla JavaScript loader animation that work when tab is not active

Downloads

1,549

Readme

favloader

npm MIT badge

Vanilla JavaScript library for loading animation in favicon that work when tab is not active

See Demo

Why this library

Basic solution with animation using canvas don't work out of the box because of limitation of timer functions in Browsers' main Thread. The library use web worker to create timer that don't stop when tab is not in focus.

You can use this library if you have time consuming calculation and people switch tabs and you wan them to be notified when application finish whatever it was doing.

Installation

You can using webpack to include the files (using require) use local file in script tag:

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

you can also get the file from unpkg.com:

<script src="https://unpkg.com/[email protected]"></script>

API

Initialization

favloader.init({
    size: 16,
    radius: 6,
    thickness: 2,
    color: '#0F60A8',
    duration: 5000
});

All options are optional (those are the defaults).

Gif support

from version 0.3.0 the library support animating GIF in browsers that don't support gif files in link tag. The feature use AJAX and canvas. So gif file need to be on same domain or on domain that enabled CORS.

To create favicon loader using GIF file, you need to include parseGIF.js file:

<script src="https://unpkg.com/[email protected]/parseGIF.js"></script>

then init the library with GIF options, that point to GIF file (the GIF file is not scaled to match favicon, and was not tested on big GIF files).

favloader.init({
    gif: 'loader.gif'
});

Custom canvas animation

From version 0.4.0 you can use custom canvas animation

var p = 0;
var reversed = false;
var width = 2;
var size = 32;
favloader.init({
  size: size,
  frame: function(ctx) {
    ctx.fillStyle = '#F00A0A';
    ctx.fillRect(p, 0, width, size);
    if (reversed) {
      p--;
      if (p === 0) {
        reversed = false;
      }
    } else {
      p++;
      if (p === size - width) {
        reversed = true;
      }
    }
  }
});

Animation

Start animating

favloader.start();
favloader.stop();

Looks best if you don't have lot of tabs or if you do when tab is not in focus.

Limitation

To restore the icon properly, after stop, you need to include default favicon:

<link rel="icon" type="image/x-icon" href="favicon.ico"/>

Changelog

0.4.4

  • allow of multiple start before initialization

0.4.3

  • throw error when calling start before init

0.4.2

  • fix clear of animation when calling init when animation is running

0.4.1

  • README fix
  • add parseGIF.min.js file

0.4.0

  • canvas animation

0.3.1

  • fix for MacOSX/Chrome
  • fix initialization before DOM is ready

0.3.0

  • GIF animation support

0.2.2

  • option fix

0.2.1

  • npm fix

0.2.0

  • make it work without onload
  • change API options

0.1.0

  • inital version

License

Copyright (c) 2018-2019 Jakub T. Jankiewicz https://jcubic.pl/me

Released under the MIT license