forked from benbarnett/jquery-animate-enhanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery-animate-css.html
135 lines (113 loc) · 5.52 KB
/
jquery-animate-css.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jquery.animate-enhanced demo</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Ben Barnett">
<!-- Date: 2010-09-01 -->
<style type="text/css" media="screen">
html {
padding:0;
margin:0;
background:#ebebeb;
}
body {
width:760px;
padding:15px;
margin:15px auto;
background:#fff;
font: 75% "Lucida Grande", "Trebuchet MS", Verdana, sans-serif;
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
}
pre {
margin:0;
padding:15px;
background:#666;
color:#fff;
font-size:120%;
width:730px;
overflow:auto;
}
#target {
padding:20px;
width:220px;
background:#0c0;
margin:20px 0;
position:relative;
}
p#results {
color:#c00;
}
</style>
</head>
<body>
<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>
<ul>
<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>
<li>opacity</li>
</ul>
<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.</p>
<h2>Demo</h2>
<div id="target">
<p>Click the button below to move me!</p>
</div>
<button>Animate left by 200px</button>
<p id="results">Awaiting button click...</p>
<pre>$('button').click(function() {
var results = $('p#results').html("Animating...");
$('#target').animate({left: '200px', width:'320px'}, 1000, function() {
results.html("callback() fired");
});
});
</pre>
<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 & 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>
<h2>Usage</h2>
<p>Usage is identical to the <a href="http://api.jquery.com/animate/">jQuery animate() function</a>, but it comes with 3 new paramaters, which are totally optional and safe to leave untouched for general use:</p>
<ul>
<li>
<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.
</li>
<li>
<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="http://www.benbarnett.net/2010/08/30/writing-html-and-css-for-mobile-safari-just-the-same-old-code/">here's why</a>).
</li>
<li>
<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>
</ul>
<h2>Download</h2>
<ul>
<li><a href="jquery.animate-enhanced.min.js">Compressed version (3.1k)</a></li>
<li><a href="scripts/src/jquery.animate-enhanced.js">Uncompressed version (6.6k)</a></li>
</ul>
<h2>Credits</h2>
<ul>
<li>Author: <a href="http://www.benbarnett.net">Ben Barnett</a> (<a href="http://twitter.com/benpbarnett">Twitter</a>)</li>
<li>Aza for <a href="http://gist.github.com/435054">his gist</a> on CSS Animation wtih jQuery</li>
<li>jonraasch for <a href="http://gist.github.com/373874">his gist on detecting CSS3 support</a></li>
</ul>
<a href="http://github.com/benbarnett/jQuery-Animate-Enhanced"><img style="position: absolute; top: 0; left: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_left_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<script type="text/javascript" src="scripts/contrib/jquery-1.4.2.js"></script>
<script type="text/javascript" src="jquery.animate-enhanced.min.js"></script>
<script type="text/javascript" charset="utf-8">
$('button').click(function() {
var results = $('p#results').html("Animating...");
$('#target').animate({left: '200px', width:'320px'}, 1000, function() {
results.html("callback() fired");
});
});
</script>
</body>
</html>