Find file
Fetching contributors…
Cannot retrieve contributors at this time
240 lines (193 sloc) 10.1 KB
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jQuery Animations with automatic CSS3 transitions when possible</title>
<meta name="generator" content="TextMate">
<meta name="author" content="Ben Barnett">
<!-- Date: 2010-09-01 -->
<style type="text/css" media="screen">
html {
body {
margin:15px auto;
font: 75% "Lucida Grande", "Trebuchet MS", Verdana, sans-serif;
h2.highlight {
.target-css, .target-dom, .target-css-leave {
padding:5px 20px;
margin:20px 0;
.target-dom {
.target-css-leave {
p#results {
div#socialise {
border-top:1px solid #ccc;
<h1>jquery.animate-enhanced plugin</h1>
<h2>Extend $.animate() to detect CSS transitions for Webkit, Mozilla and Opera and convert animations automatically. Compatible with IE6+</h2>
<h3>Properties supported: (more to come)</h3>
<li>left : using <em>translate(x, y) or translate3d(x, y, z)</em></li>
<li>top : using <em>translate(x, y) or translate3d(x, y, z)</em></li>
<h3>New features in v0.64:</h3>
<li>Animation 'queue' support (including .delay())</li>
<li>Context issues fixed on callback(); 'this' = element passed in</li>
<li>$.translate() method to calculate x/y transforms from CSS3 Matrix</li>
<li>Support for <b>$.fn.stop([clearQueue, jumpToEnd, leaveTransforms])</b></li>
<li>Tweaks for jQuery 1.4.3</li>
<li>Enhance 'width' and 'height' properties</li>
<li>Compatible with .fadeIn(), .fadeOut(), .slideUp(), .slideDown() and slideToggle()</li>
<li>jQuery shortcuts ("fast", "slow")</li>
<li>Use relative values (+= / -=) for animations</li>
<li>Use strings, numbers, 'px' values and the plugin will sanitize them</li>
<li>Callback function is now optional (bug from previous version)</li>
<li>Apply animations to any number of elements and CSS3/DOM animations will take care of themselves</li>
<li>Multiple bug fixes</li>
<li>Licensed under <a href="">MIT License</a></li>
<p>Note that any properties not mentioned above will simply be handled by the standard jQuery $.animate() method. This plugin adds new functionality without taking any away. Requires jQuery 1.3.2+</p>
<p>The animation types can be used in any combination, and with any number of elements. See 3 different types below:</p>
<div class="target-css">
<p>Animate with CSS3 <b>(leaveTransforms:false)</b></p>
<div class="target-css-leave">
<p>Animate with CSS3 <b>(leaveTransforms:true)</b></p>
<div class="target-dom">
<p>Animate with DOM <b>(avoidTransforms:true)</b></p>
<button id="start">Animate</button>
<p id="results">Awaiting button click...</p>
<script src=""></script>
<h2>What it does</h2>
<p>The plugin will analyse the properties you're animating on, and select the most appropriate method for the browser in use. This means your transitions on <strong>left, top and opacity</strong> will convert to a <strong>CSS3 transition</strong> on Webkit &amp; Mozilla agents that support it, and Opera 10.50+. If the user is on a browser that has no CSS3 transitions, this plugin knows about it and won't get involved. Silent degradation :)</p>
<p>Multiple callback mechanisms are created internally to monitor for DOM manipulation and for all '<strong>transitionend</strong>' CSS3 events to be picked up. This means you have one neat callback() for the whole animation regardless on whether the plugin is using CSS3, DOM, or both for its animations.</p>
<p>Progressively enhanced CSS3 animations without having to do any browser detection or special CSS, therefore using the same Javascript across your applications and websites.</p>
<p>As this plugin uses CSS3 translate where available, there is an internal callback mechanism to reset the 'left' and/or 'top' properties so that your layout is unaffected.</p>
<p>Usage is identical to the <a href="">jQuery animate() function</a>, but it comes with 3 new paramaters, which are totally optional and safe to leave untouched for general use:</p>
<strong>avoidTransforms</strong>: (Boolean)<br>
By default the plugin will convert left and top animations to the CSS3 style -webkit-transform (or equivalent) to aid hardware acceleration. This functionality can be disabled by setting this to true.
<strong>useTranslate3d</strong>: (Boolean)<br>
By default the plugin will use 2d translations due to wider browser support. Set this to true to use translate3d instead. Recommended for iPhone/iPad development (<a href="">here's why</a>).
<strong>leaveTransforms</strong>: (Boolean)<br>
By default if the plugin is animating a left or a top property, the translate (2d or 3d depending on setting above) CSS3 transformation will be used. To preserve other layout dependencies, once the transition is complete, these transitions are removed and converted back to the real left and top values. Set this to <strong>true</strong> to skip this functionality.
<li><a href="">Compressed version</a> (5.17KB, <i>1.91KB gzipped</i>)</li>
<li><a href="">Uncompressed version</a> (13.94KB, <i>4.33KB gzipped</i>)</li>
<li>Author: <a href="">Ben Barnett</a> (<a href="">Twitter</a>)</li>
<li>Aza for <a href="">his gist</a> on CSS Animation wtih jQuery</li>
<li>jonraasch for <a href="">his gist on detecting CSS3 support</a></li>
<p>Licensed under the <a href="">MIT License</a>.</p>
<div id="socialise">
<a href="" class="twitter-share-button" data-count="horizontal" data-via="benpbarnett">Tweet</a><script type="text/javascript" src=""></script>
<h3>Please DO NOT put bug reports on the comments below. Feel free to report any issues on the <a href="">Github Issues</a> page.</h3>
<div id="disqus_thread"></div>
<script type="text/javascript">
* var disqus_identifier; [Optional but recommended: Define a unique identifier (e.g. post id or slug) for this thread]
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
<noscript>Please enable JavaScript to view the <a href="">comments powered by Disqus.</a></noscript>
<a href="" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
<a href=""><img style="position: fixed; top: 0; left: 0; border: 0;" src="" alt="Fork me on GitHub" /></a>
<script type="text/javascript" src="scripts/contrib/jquery-1.4.3.js"></script>
<script type="text/javascript" src="scripts/src/jquery.animate-enhanced.js"></script>
<script type="text/javascript" charset="utf-8">
$('button#start').click(function() {
var results = $('p#results').html("Animating..."),
button = $(this).attr('disabled', 'disabled');
// CSS3 Container
$('.target-css').animate({left: "+=200px", width:320 }, 1500, function() {
results.html('first callback() fired, reversing...');
$(this).animate({left: "-=200px", width:280 }, 1500, function() {
results.html("second callback() fired");
$('button:not(#start)').attr('disabled', 'disabled');
// CSS3 Container (leaveTransforms)
$('.target-css-leave').animate({left: "+=200px", width:320, leaveTransforms:true }, 1500, function() {
$(this).animate({left: "-=200px", width:280, leaveTransforms:true }, 1500);
// DOM container
$('.target-dom').animate({left: "+=200px", width:320, avoidTransforms:true }, 1500, function() {
$(this).animate({left: "-=200px", width:280, avoidTransforms:true }, 1500);
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-8825585-11']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
<script type="text/javascript">
var disqus_shortname = 'benbarnett';
(function () {
var s = document.createElement('script'); s.async = true;
s.src = '';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);