Coder Social home page Coder Social logo

mgol / jquery-requestanimationframe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gnarf/jquery-requestanimationframe

1.0 2.0 0.0 202 KB

Replaces the standard jQuery timer loop with requestAnimationFrame where supported. Requires jQuery 1.8

License: MIT License

JavaScript 84.32% HTML 15.68%

jquery-requestanimationframe's Introduction

jQuery requestAnimationFrame

Replaces the standard jQuery timer loop with requestAnimationFrame where supported.

NOTE: jQuery 3.0.0 & newer uses requestAnimationFrame natively if it's available in the browser. This plugin is only needed for older versions of jQuery. If it detects jQuery 3.0 or newer it warns and does nothing.

Requires jQuery 1.8+

What is requestAnimationFrame?

requestAnimationFrame is a W3C spec (at Candidate Recommendation level) that attempts to improve our animation performace by better syncing up with the frame rate of the browser. For more information, read this article on Jank Busting

Why should I use it?

To quote part of the Jank Busting article:

  • Animations in background tabs get paused, conserving system resources and battery life.

  • If the system can't handle rendering at the screen's refresh rate, it can throttle animations and produce the callback less frequently (say, 30 times a second on a 60Hz screen). While this drops framerate in half, it keeps the animation consistent -- and as stated above, our eyes are much more attuned to variance than framerate. A steady 30Hz looks better than 60Hz that misses a few frames a second.

Download

Download the production version or the development version of version 0.1.2.

In your web page:

<script src="jquery.js"></script>
<script src="jquery.requestanimationframe.min.js"></script>

Documentation

There isn't anything you need to do other than include the jquery.requestanimationframe.js file to use requestAnimationFrame.

You should however beware of the first point above: Animations in background tabs get paused.

This means if you are using a setInterval or setTimeout to queue up new animations, when the user returns to the backgrounded page, jQuery will finally see an animation finish, and then start playing everything queued. There is more information about potential workarounds in jQuery Core Bug #9381

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Also, please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "src" subdirectory!

Release History

  • 0.2.1, 0.2.2 - Oct 26 2016
    • README updates
  • 0.2.0 - Oct 26 2016
    • Started publishing to npm ๐ŸŽ‰
    • Added Browserify/RequireJS/Webpack support
    • Dropped the rAF polyfill
    • Stopped using the vendor-prefixed rAF version; such browsers are now treated as if they didn't have rAF at all
  • 0.1.2 - Apr 15 2013
    • Removed o prefix - opera only ships with unprefixed rAF
  • 0.1.1 - Mar 5 2013
    • Removed ms prefix
  • 0.1.0 - Jan 13 2013
    • Initial Release

License

Copyright (c) 2012 Corey Frang Licensed under the MIT license.

jquery-requestanimationframe's People

Contributors

acusti avatar danmer avatar gnarf avatar jantimon avatar kswedberg avatar mgol avatar paulirish avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.