• Stars
    star
    2,004
  • Rank 23,109 (Top 0.5 %)
  • Language
    HTML
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A custom element for flexible GIF playback

<x-gif>

The GIF tag the internet deserves

Usage

<x-gif> is a web component for flexible GIF playback. Speed them up, slow them down, play them in reverse, synch multiple beats to a rhythm, synch them to audio, whatever you like.

<x-gif src="probably_cats.gif"></x-gif>

###Playback modes:

Mutually exclusive. Can't be changed once initialised (create a new x-gif if you want a new mode)

speed="1.0" (default mode) Plays back the GIF at its natural framerate multiplied by the value of the attribute. Can be updated and will have immediate effect.

sync Defers playback to an external object. The DOM element will then expose a clock function to facilitate playback. Cannot be changed.

bpm="120" Syncs GIFs to a given beats-per-minute. If multiple x-gifs are on the page, they will all be synced together. By default, will spread long GIFs over multiple beats, unless the snap option is also included. Uses sync and clock under the hood. Can be changed and will take immediate effect.

###Options:

stopped Regardless of playback mode, this will prevent the GIF from animating. Removing this attribute resumes playback. In speed mode, the GIF will always resume playback from the beginning.

fill Causes the GIF to expand to cover its container, like if you had used background-size: cover; background-position: 50% 50% with a normal GIF. Without fill, an x-gif behaves like an inline-block element, just like a normal tag.

n-times="3.0" (speed mode only) Stops playback (by adding the attribute stopped) after a set number of times. Can be fractional e.g. 0.9 will play the first 90% of the GIF then stop. Removing the stopped attribute will restart the playback.

snap (sync & bpm modes only) Instead of allowing longer GIFs to sync to multiple beats, force them to fit into only one.

ping-pong Boolean attribute. Plays the GIF front-to-back then back-to-front, which looks more awesome for some GIFs. Works with all playback modes. Can be removed/added at any time.

###Debugging:

debug Turns on debug output from the Gif Exploder, which can help track down errors with some GIFs being parsed incorrectly.

exploded For visual inspection of the frames. Stops playback, and renders each frame out side-by-side. Many frames will appear semi-transparent, because that's how GIFs work. But this might come in handy.

##What does it do?

  • AJAX fetches the GIF as a binary stream
  • Slices the GIF into frames like a total boss
  • Stacks the frames one on top of the other
  • Starts a requestAnimationFrame loop to play back the gif at its natural frame rate

Here's a demo! It just might work in your browser!

Check out the rest of the demos

Usage

<script>
  if ('registerElement' in document
    && 'createShadowRoot' in HTMLElement.prototype
    && 'import' in document.createElement('link')
    && 'content' in document.createElement('template')) {
    // We're using a browser with native WC support!
  } else {
    document.write('<script src="https:\/\/cdnjs.cloudflare.com/ajax/libs/polymer/0.3.4/platform.js"><\/script>')
  }
</script>
<link rel="import" href="x-gif.html">

This will detect support for Web Components, shim them if needed, then load x-gif with a HTML import.

Roadmap

  • Web Component - YES! (zero-dependencies on Chrome 36!)
  • Polymer element - Nah, just use the Web Component
  • Angular directive - Nah, just use the Web Component
  • React component - Nah, just use the Web Component
  • Ember component - Nah, just use the Web Component

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT License

More Repositories

1

react-snapshot

A zero-configuration static pre-renderer for React apps
JavaScript
1,655
star
2

git-smart

Add some smarts to your git workflow
Ruby
420
star
3

typeslab

Simple, shareable typographic posters
JavaScript
284
star
4

loopgifs

JavaScript
193
star
5

djgif

JavaScript
161
star
6

npx-import

TypeScript
161
star
7

shellac

Coat your shell scripts in something a bit more beautiful
TypeScript
155
star
8

jspm-server

A live-reloading development server for JSPM
JavaScript
145
star
9

jspm-loader-css

JavaScript
50
star
10

web-directions-talk

JavaScript
43
star
11

Snap.svg-cjs

JavaScript
40
star
12

create-react-app-snapshot

A demo of react-snapshot and create-react-app
JavaScript
33
star
13

x-beat

A Web Component for generating a continuous stream of beats from (currently) MIDI and (soon) Web Audio for the synchronising of GIFs to music.
JavaScript
32
star
14

css-components-demo

JavaScript
30
star
15

run-a-gist

Ruby
27
star
16

jspm-loader-jsx

A hot-reloading JSX plugin for JSPM
JavaScript
21
star
17

jspm-loader-css-modules

JavaScript
20
star
18

dollhouse

A place to manage your babushkas
Ruby
15
star
19

glenmaddern.com

HTML
9
star
20

angularjs-coffeescript-sinatra-template

8
star
21

webpack-from-first-principles

CSS
8
star
22

plugin-postcss

JavaScript
5
star
23

mohole

It's mouseHole for mobiles!
JavaScript
5
star
24

angularjs-workshop

Slides and code for my half-day AngularJS workshop
JavaScript
4
star
25

css-modules-injector

4
star
26

fireblog

JavaScript
3
star
27

geelen.github.com

Pages
CSS
3
star
28

gitwatch

Like Baywatch, but with more Git and less Hasselhoff
Scala
3
star
29

djjour

What was duke, then dukejour, is now DJjour (where the DJ stands for dukejour)
Ruby
3
star
30

babushka-deps

Ruby
3
star
31

jplanner

Scala
3
star
32

scaml

scaml
Scala
3
star
33

gifs-vs-web-components

CSS
3
star
34

github-displayer

A drop-dead simple way of taking html files on github projects and serving them as html
Ruby
3
star
35

gmfs

Java
3
star
36

pacifism

A ripoff of the geo-wars mode
Scala
2
star
37

sc-perf-testing

JavaScript
2
star
38

pages-functions-test

JavaScript
2
star
39

react-blog

CoffeeScript
2
star
40

tag-parser

Ruby
2
star
41

primefinder

something simple in scala
Scala
2
star
42

a-gif-odyssey

CSS
2
star
43

box

Boost Dox
Ruby
2
star
44

canvasgif

JavaScript
2
star
45

slinky2-appengine-demo

Taken the slinky2 demo and set it up to deploy to Google's App Engine
2
star
46

mohole-scala

Mohole in Scala on the GAE
Scala
2
star
47

better-hn

better-hn
Ruby
2
star
48

scala-guestbook

A scala version of the Google App Engine guestbook demo app
2
star
49

lazyrb

Playing around with lazy evaluation in ruby
Ruby
2
star
50

scails

Scails
2
star
51

assemble-talk

JavaScript
2
star
52

yamltypedtranslator

A mashup of FJ and jvyaml
2
star
53

fj-yaml

A typed translator for arbitrary YAML
Java
2
star
54

light-table

JavaScript
2
star
55

melbjs-demo

A demo of AngularJS I presented at MelbJS on Jan 8, 2013
CoffeeScript
2
star
56

beat-detect

JavaScript
2
star
57

sc-134

JavaScript
1
star
58

this-kind-of-agility

thiskindofagility.com
HTML
1
star
59

react-mfe-oct-4

JavaScript
1
star
60

deno-blog-example

Nunjucks
1
star
61

hazzard

The other half of Duke
Ruby
1
star
62

sbt-plugins

plugins for sbt
Scala
1
star
63

aquarelle

1
star
64

eleventy-testing

JavaScript
1
star
65

minimum-viable-emoji

1
star
66

objects-on-rails

Ruby
1
star
67

the-z-dimension

JavaScript
1
star
68

polywin

Use multiple languages ftw
Ruby
1
star
69

despacito

JavaScript
1
star
70

traits

Subatomic Styles
JavaScript
1
star
71

goodfilms-placeholder

Ruby
1
star
72

goodfilms-iphone

iphone app for goodfil.ms
Objective-C
1
star
73

fab-cloudflare-error

JavaScript
1
star
74

angular-html5-routing-bug

Routing table redirects to /, but /#something breaks it
Ruby
1
star
75

as_seen_by

The Dev Team, as seen by themselves
1
star
76

superposition

JavaScript
1
star
77

groundhog

Keep repeating the same day, er transaction.
Ruby
1
star
78

allsofterworlds

A consumable alternative to asofterworld.com
Ruby
1
star
79

flux-ai-image-generator

TypeScript
1
star