Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

play-js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

play-js

Agnostic frame-skipping animation library

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Play.js

Agnostic frame-skipping animation library

Performs an abstract transition for a fixed amount of time, regardless of the frame rate of the page (frame skipping.) Calls an onFrame callback with a 0-to-1 float ratio (representing the progress of the transition) as often as the browser can perform.

// Run a transition for one second
Play.start({
  time: 1,
  onFrame: function(r) {
    console.log('Animation is at ' + (r * 100).toFixed(2) + '%');
  }
});

// A custom transition easing can be set using the "easing" option, otherwise
// it defaults to linear.
Play.start({
  time: 0.1,
  easing: function(r) {
    // Similar to the default jQuery "swing" easing ($.easing.swing)
    return 0.5 - Math.cos(r * Math.PI) / 2;
  },
  onFrame: function(r) {
    // The first and last values will be closer, as the transition grows faster
    // in middle
    console.log(r);
  }
});

// Starting an animation returns a reference to its instance, exposing a few
// API methods
var myAnimation = Play.start({time: 5});

// You can stop an animation at any time...
Play.stop(myAnimation);
// ...or end it. The difference being that this time the onFrame handler will
// also be called on last time, with maximum ratio (1), as if the entire time
// for that animation had passed
Play.end(myAnimation);

// Another thing you can do is start a transition from a specific point in its
// development. This animation will go from 0.5 to 1 ratio and will last 500ms
Play.start({time: 1, ratio: 0.5});

// The beauty of the onFrame handler lays in its simplicity. You can use the
// frame ratio in any way you'd like, from rendering a progress bar to all
// sorts af complex DOM transitions
Play.start({time: 5, function(r) {
  $('.my-element').css({top: r / 2, left: r});
}});

// Play.js can also be installed as a npm package
var Play = require('play-js').Play;

FAQs

Package last updated on 28 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts