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

js-gifplayer

v2.5.0

Published

GIF player, which allows you to control/draw every single frame separately.

Downloads

28

Readme

GIF player, which allows you to control/draw every single frame separately.

Navigation

§0 Installation

npm i js-gifplayer

§1 Initialization

Import into JS module

import GIFPlayerV2 from "js-gifplayer" // or path to GIFPlayerV2.js

Usage

HTML

<div id="wrapper"></div>

JS

const sources = 'gif1.gif' || ['gif1.gif', 'gif2.gif'] 
const player = new GIFPlayer(sources, '#wrappper', {
    player: {
        //player config
    },
    plugins: [/* Plug-in names */],
    //plug-in name in lowercase: { plug-in config }
})

§2 Parameters

  • GIF links (multiple GIFS can be passed).
  • Wrapper selector.
  • Options:
    • player: {...} This is the workspace where we are going to assign our parameters.
    • fps: sets fps. Default is 60.
    • frame: sets starting frame (if passed index is invalid, player will run from default value). Default is 0.
    • autoplay: sets autoplay. Default is false.
    • direction: GIFPlayerV2.states.BACKWARD || GIFPlayerV2.states.FORWARD sets the play direction. Default is GIFPlayerV2.states.FORWARD.
    • plugins: binds built-in plug-ins [GIFPlayer.AllPlugins.PLG_NAME...].
    • PLG_NAME: { ... } set up plug in config.

§3 Functions

Setters

.direction set play direction. .frame set current frame. .fps set fps limiter.

Getters

.all all internal states of the player. .canvas canvas HTML element. .wrapper wrapper element. .state player state. .frames_length frames count. .current_frame_index current frame index. .current_frame current frame. .direction playing direction. .fps fps limiter. .urls gifs urls and its frame indexes. get_frame(index) also a getter, but it's function because you have to pass an index.

Controls

play() play the GIF. play_forward() set direction to GIFPlayer.states.FORWARD and play. play_backward() set direction to GIFPlayer.states.BACKWARD and play. pause() pause the GIF. stop() pause the GIF and jump back to the first frame. reverse() reverse playing direction. step(count) jumps count frames forward. (Depends on direction) step_back(count) jumps back count frame. (Depends on direction)

GIF Mutators

shuffle_frames() randomly shuffles frames. remove_frames(...indices) remove frames. add_frames(...imgs) push new frames. remove_gifs(...gifs) remove GIFs frames. add_gifs(...gifs) push new GIFs frames.

§4 Global variables

static States = Object.freeze({
    LOADING: 0,  //loading states
    READY: 1,
    PAUSED: 2,
    PLAYING: 3,
    ERROR: 4,

    FORWARD: 5, //play direction states
    BACKWARD: 6,
})
static AllPlugins = Object.freeze({
    Scroller: 'scroller',
    GUI: 'gui'
})

§5 Plug-Ins

Note: some plug-ins overwrite functions. Currently exist 2 plug-ins:

  • Scroller GIFPlayerV2.AllPlugins.Scroller
    • Name: Scroller.
    • Description: synchron play-on-scroll animation.
    • Options:
      • flow set the animation flow during scrolling. Default [0, 1].
      • target set the scrolling element.
  • GUI GIFPlayerV2.AllPlugins.GUI
    • Name: GUI.
    • Description: Interactive GUI Controller.
    • Options:
      • hidden hide GUI visuals. Default false.
      • animationDuration set GUIs animation duration.

§6 Note

Some GIFs may have artifacts when running backwards. The most common reason is compression, which removes unchanged pixels from the next frame.