Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gifffer

> 编程语言
Open source

A tiny JavaScript library that prevents the autoplaying of the animated Gifs

780 stars0 likes2 views
WebsiteGitHub

About

A tiny JavaScript library that prevents the autoplaying of the animated Gifs

Gifffer


JavaScript library that prevents the autoplaying of the animated Gifs.

Demo

http://krasimir.github.io/gifffer

Usage

Include gifffer.min.js in your page.

xml

Instead of setting src attribute on your image use data-gifffer.

xml

At the end, call Gifffer(); so you replace the normal gifs with playable gifs. For example:

javascript
window.onload = function() {
  Gifffer();
}

For accessibility reasons, instead of setting alt attribute on your image, you may use data-gifffer-alt (optional).

xml

The Gifffer function returns an array of nodes that could be used to simulate clicks. For Example:

javascript
window.onload = function() {
  var gifs = Gifffer();

  setTimeout( function() {
    gifs[0].click(); //will play the first gif
  }, 1000);
}

Gifffer will show the controls immediately if you set data-gifffer-width and data-gifffer-height even if the image is not fully loaded.

xml

(data-gifffer-width accepts percentages value)

Have in mind that the library keeps the value of the class and id attributes. They are applied to the newly created element.

If you want to stop the Gif and reset it to its original position afetr a given time interval use data-gifffer-duration (in milliseconds).

Module Loading (Webpack or Angular ect)

Install npm module

bash
npm i --save gifffer

Import

import Gifffer from 'gifffer';

let gifs = Gifffer();

Typescript

bash
npm i --save-dev @types/gifffer

Styling

The Gifffer() function accepts a few options for styling:

Gifffer({
  playButtonStyles: {
    'width': '60px',
    'height': '60px',
    'border-radius': '30px',
    'background': 'rgba(0, 0, 0, 0.3)',
    'position': 'absolute',
    'top': '50%',
    'left': '50%',
    'margin': '-30px 0 0 -30px'
  },
  playButtonIconStyles: {
    'width': '0',
    'height': '0',
    'border-top': '14px solid transparent',
    'border-bottom': '14px solid transparent',
    'border-left': '14px solid rgba(0, 0, 0, 0.5)',
    'position': 'absolute',
    'left': '26px',
    'top': '16px'
  }
});

That's about the play button. Note that if you decide to use playButtonStyles or playButtonIconStyles you have to provide the full style of the elements. For example providing only { top: '20px' } property results in top:20px;.

How it works

It replaces your tag with newly generated that contains only the first frame (roughly) of your animated Gif. It creates a play button on top of it and when the element is clicked it returns the original image.

Compatibility

Chrome, FF, Safari, Opera, IE9+

Side effects

Your tag is replaced by a. Consider the fact that it is a block element.

Inspiration

http://stackoverflow.com/a/4276742/642670

Issues· 13 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言