Giter Site home page Giter Site logo

jogwheel's Introduction

Take control of your CSS keyframe animations

jogwheel


Health

ci coverage climate

Availability

npm cdn npm-dl

Activity

pr issue

Conventions and standards

dependency-manager release-manager ecma codestyle license commitizen

About

jogwheel gives you the power to take full control of your CSS keyframe animations via JavaScript.

  • separation of concerns: Declare animations with CSS
  • full control: Play, pause and scrub your animations
  • animation sequences: No brittle fiddling with animationEnd
  • world peace

Install

jogwheel is available on npm.

npm install --save jogwheel

Usage

⚠️ Please note jogwheel assumes Element.prototype.animate is defined and returns a valid WebAnimationPlayer instance. To achieve this you will have to include a WebAnimation polyfill, web-animations-js by Google is recommended.

The usage examples show recommended ways to include the polyfill.

CommonJS

jogwheel exposes its API as CommonJS module. Using the export and bundling your JavaScript with browserify, webpack or rollup is recommended.

// import the polyfill
import 'web-animations-js';

// import jogwheel
import jogwheel from 'jogwheel';

// Select target element
const element = document.querySelector('[data-animated]');

// Construct jogwheel instance from element
const player = jogwheel.create(element);

// Jump halfway into the animation
player.seek(0.5);

CDN

jogwheel provides prebundled downloads via wzrd.in. Either embed or download the standalone bundle. Given you do not use a module system the standalone build will pollute window.jogwheel. This usage is viable but not recommended.

Fast track example

# Install cross-platform opn command
npm install -g opn-cli

# Download example
curl -L https://git.io/vreEP > jogwheel-example.html

# Open example in default browser
opn jogwheel-example.html

All the code

<!doctype html>
<html>
  <head>
    <title>CDN example</title>
  </head>
  <style>
    @keyframes bounce {
      0%, 100% {
        transform: none;
      }
      50% {
        transform: translateY(100%);
      }
    }

    @-webkit-keyframes bounce {
      0%, 100% {
        -webkit-transform: none;
      }
      50% {
        -webkit-transform: translateY(100%);
      }
    }

    [data-animated] {
      animation: bounce 10s;
      animation-fill-mode: both;
      animation-play-state: paused;
      animation-iteration-count: infinite;
      display: inline-block;
      height: 100px;
      width: 100px;
      background: #333;
      border-radius: 50%;
      color: #fff;
      font-family: sans-serif;
      line-height: 100px;
      text-align: center;
    }
    [data-animated]:nth-child(2) {
      animation-delay: 2.5s;
    }
    [data-animated]:nth-child(3) {
      animation-delay: 5s;
    }
  </style>
  <body>
    <div data-animated>Paused 0.5</div>
    <div data-animated>Paused 0.5</div>
    <div data-animated>Paused 0.5</div>
    <script src="https://wzrd.in/standalone/web-animations-js@latest"></script>
    <script src="https://wzrd.in/standalone/jogwheel@latest"></script>
    <script>
      var elements = document.querySelectorAll('[data-animated]');
      var player = jogwheel.create(elements);
      player.seek(0.5);

      setTimeout(function(){
        player.play();
        for (var i = 0; i < elements.length; i += 1) {
          elements[i].innerText = 'Playing';
        }
      }, 5000);
    </script>
  </body>
</html>

See API Documentation for details and examples for more use cases.

Browser support

jogwheel performs cross browser testing with SauceLabs

Browser Support

Limitations

Depending on the WebAnimations implementation you choose there are some limitations for properties usable with jogwheel.

Feature Test Issue Blink Gecko web-animations-js 2.1.4 web-animations-next 2.1.4
animation-timing-function Link #161 ⚠️ ⚠️ ⚠️ ⚠️
filter Link #162 ⚠️ ⚠️ ⚠️ ⚠️

Development

You dig jogwheel and want to submit a pull request? Awesome! Be sure to read the contribution guide and you should be good to go. Here are some notes to get you coding real quick.

# Clone repository, cd into it
git clone https://github.com/marionebl/jogwheel.git
cd jogwheel
# Install npm dependencies
npm install
# Start the default build/watch task
npm start

This will watch all files in source and start the appropriate tasks when changes are detected.

Roadmap

jogwheel is up to a lot of good. This includes but is not limited to

  • super-awesome cross-browser tests
  • unit-tested documentation code examples, because rust isn't the only language that can do cool dev convenience stuff
  • an interactive playground and animation editor
  • a plug-and-play react integration component

See Roadmap for details.


jogwheel v1.4.5 is built by Mario Nebl and contributors with ❤️ and released under the MIT License.

jogwheel's People

Contributors

greenkeeperio-bot avatar marionebl avatar meandmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jogwheel's Issues

Jogwheel ignores animation-delay

Hi.

Can jogwheel sync two animations on one timeline? For example: Have one @keyframe rotation { … } applied to two elements, where the second element has a animation-delay set. This makes the elements behaving like a rotation for an inifinite animation-iteration.

Is this something we can augment by using one jogwheel player?

It seems to us that jogwheel is ignoring the animation-delay set on that element and is playing both animations in unison – not chaining them.

Can we remove Jogwheel after applying it?

When we create an instance of Jogwheel, it takes over the animations for us. Can we call some sort of method to release control from Jogwheel and return everything to it's previous state? My goal is to use Jogwheel to skip to a specific part of an animation, pause, then remove Jogwheel, and the animation is still paused via animation-play-state but untouched otherwise.

Perhaps some sort of ::release() method?

Check for css animation

Jogwheel should unplug automatically when there is no css animation definend and plug in automatically when the animation is defined again. This is very important for animations which are defined through media queries.

Jogwheel can't control filters

Jogwheel can't control filters. I've tried -webkit-filter: sepia and -webkit-filter: blur. It's not showing or tweening them.

Provide interactive playground

Provide an interactive playground with

  • Live code editing of CSS, JS, HTML
  • Look-behind and look-ahead views of the given Jogwheel instance

BRCDN.org fails to serve files for example

Hi everyone. Love the library but I ran into an issue when trying to run the example fast-track demo.

brcdn.org seems to have a build error for the hosted file so the demo is unable to run. For example this url from the demo:
https://www.brcdn.org/jogwheel/1.4.3/?standalone=jogwheel&uglify=true
It seems to be hanging on the uglify script.

Fails to load and instead produces this error on brcdn:

Error: Build Error 1: time="2016-04-29T14:06:33-04:00" level="fatal" msg="Error response from daemon: Cannot start container 172d89b32345ceab48aa8cc8dd13eeef5c646aa18797e20a9c7295b4bc2da458: fork/exec /var/lib/docker/init/dockerinit-1.5.0: cannot allocate memory" 
(while building [email protected])
   at /root/instances/www.brcdn.org/blue/lib/build.js:116:13
   at /root/instances/www.brcdn.org/blue/node_modules/promise/lib/core.js:33:15
   at flush (/root/instances/www.brcdn.org/blue/node_modules/promise/node_modules/asap/asap.js:27:13)
   at process._tickCallback (node.js:442:13)

Also, the web-animations-js libarary does not seem to be available on brcdn.org at all.

onFinish handlers

Hey, how can I be alerted that a given animation has finished?

I've been looking through the code and I've seen multiple references to 'finished' members. There's the _finishHandlers private member and there's the onfinish player member, (which I believe was replaced with finished according to the W3 spec?). I've also tried observe-js and couldn't get that working, but clearly that's a hack, and using a setInterval call to watch for the _isFinished flag changing doesn't help.

Appending both promises and anonymous functions to these don't yield the result I'm after, and there's nothing I can find in the documentation.

What's the correct method for adding a callback handler to an animation?

Installation for non-node users

Some people don't use Node, or grunt etc - and they just want to use this client-side JS library. It would be incredibly useful to provide basic instructions for people to install and use the library in a basic application without any other dependencies (which file should be included... index.js? etc).

JogWheel fails when `element.animate` is undefined

JogWheel initializing fails with

Uncaught TypeError: Function.prototype.toString is not generic

when the animate method on the passed HTMLElements is undefined.

  • Handle unpolyfilled environments / environments without native DOM gracefully
  • Log a warning about the missing method
  • Be helpful about missing polyfill if HTMLElement.prototype.animate is not defined

First part animation is being played at wrong speed

The first part of an animation is being played too slowly. Here's a codepen. If you remove the Jogwheel JS and then let the animation play, it plays at the correct speed, but when you add Jogwheel it slows the animation down (might be a little hard to see but it's there).

Integration tests fail sporadically

Integration tests for

  • Firefox [40..44]
  • Android {4.4, 5.1}

fail sporadically.

This appears to be a problem with the simple-animation test and integration test setup itself.

Can not seek; duration is undefined

In Chrome (version 46.0.2490.86) there is no effect defined on this.player in https://github.com/marionebl/jogwheel/blob/master/source/library/index.js#L129. Thus seek() results in an error.

element.animate(keyframes, options) was called with these options (manipulated to work around two bugs):

{duration: 1000, iterations: 100, easing: "linear", fill: "both"}

This is my css:

@keyframes spin {
    from {
        transform: rotate(0);
    }
    to {
        transform: rotate(-360deg);
    }
}

[data-animated] {
    animation: spin 1s linear 100;
    animation-fill-mode: both;
    animation-play-state: paused;
}

JS Error in jogwheel

Hi,

there is an error in jogwheel. I'll investigate this.

Browser: Chrome

init-player.js:92
Uncaught TypeError: Failed to execute 'animate' on 'Element': The provided double value is non-finite.

Basic example should work out of the box.

Your basic example doesn`t work out of the box. I think if someone wants to try this out, he just should need to copy it in a file and open it in a browser. Both script tags from the cdn are blocking anything else so nothing is happening ...

Have a great day! Max

<!doctype html>
<html>
  <head>
    <title>CDN example</title>
  </head>
  <style>
    @keframes bounce {
      0% {
        transform: none;
      }

      25% {
        transform: translateY(-100%);
      }

      50% {
        transform: none;
      }

      75% {
        transform: translateY(100%);
      }

      100% {
        transform: none;
      }
    }

    [data-animated] {
      animation: bounce 1s;
      animation-fill-mode: both;
      animation-play-state: paused;
      height: 100px;
      width: 100px;
      background: #333;
      border-radius: 50%;
    }
  </style>
  <body>
    <div data-animated></div>
    <script src="https://www.brcdn.org/web-animations-js/latest/?standalone=web-animations-js&uglify=true" />
    <script src="https://www.brcdn.org/jogwheel/latest/?standalone=jogwheel&uglify=true" />
    <script>
      var element = document.querySelector('[data-animated]');
      var player = JogWheel.create(element);
      player.seek(0.5).play();
    </script>
  </body>
</html>

Support multiple players per JogWheel instance

It should be possible to do both

// This is the current behavior
const element = document.querySelector('.foo');
const wheel = JogWheel.create(element);

and

// This is additional behavior
const elements = document.querySelectorAll('.foo');
const wheel = JogWheel.create(elements);

unsafe camelcase

See camelcase-css.

I haven't gone through all of this project's code to see if it handles this manually, but the above library can help reduce complexity.

Testing requires a lot of stubbing

Testing jogwheel requires a lot of stubbing for non-browser environments.

This affects

  • jsdom
  • node

Publish the stubs written for jogwheel found in the unit tests as seperate module.

@KnisterPeter Would love your input on this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.