-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.html
331 lines (321 loc) · 20.7 KB
/
index.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<!DOCTYPE html>
<html>
<head>
<title>doc</title>
<style>
/*github.com style (c) Vasily Polovnyov <[email protected]>*/
pre code {
display: block; padding: 0.5em;
color: #333;
background: #f8f8ff
}
pre .comment,
pre .template_comment,
pre .diff .header,
pre .javadoc {
color: #998;
font-style: italic
}
pre .keyword,
pre .css .rule .keyword,
pre .winutils,
pre .javascript .title,
pre .nginx .title,
pre .subst,
pre .request,
pre .status {
color: #333;
font-weight: bold
}
pre .number,
pre .hexcolor,
pre .ruby .constant {
color: #099;
}
pre .string,
pre .tag .value,
pre .phpdoc,
pre .tex .formula {
color: #d14
}
pre .title,
pre .id {
color: #900;
font-weight: bold
}
pre .javascript .title,
pre .lisp .title,
pre .clojure .title,
pre .subst {
font-weight: normal
}
pre .class .title,
pre .haskell .type,
pre .vhdl .literal,
pre .tex .command {
color: #458;
font-weight: bold
}
pre .tag,
pre .tag .title,
pre .rules .property,
pre .django .tag .keyword {
color: #000080;
font-weight: normal
}
pre .attribute,
pre .variable,
pre .lisp .body {
color: #008080
}
pre .regexp {
color: #009926
}
pre .class {
color: #458;
font-weight: bold
}
pre .symbol,
pre .ruby .symbol .string,
pre .lisp .keyword,
pre .tex .special,
pre .prompt {
color: #990073
}
pre .built_in,
pre .lisp .title,
pre .clojure .built_in {
color: #0086b3
}
pre .preprocessor,
pre .pi,
pre .doctype,
pre .shebang,
pre .cdata {
color: #999;
font-weight: bold
}
pre .deletion {
background: #fdd
}
pre .addition {
background: #dfd
}
pre .diff .change {
background: #0086b3
}
pre .chunk {
color: #aaa
}
</style>
</head>
<body>
<p><a style="float:right" href="https://github.com/bkwld/tram">[view on github]</a> v0.8.3</p>
<h1 id="tram-js">tram.js</h1>
<p>Cross-browser CSS3 transitions in JavaScript.</p>
<h2 id="about">About</h2>
<p>The idea behind Tram is to take the performance and flexibility of CSS transitions and define them in JavaScript - offering a more powerful, expressive API with auto-stopping, sequencing, and cross-browser fallbacks.</p>
<p>Tram currently depends on jQuery for a few reasons: (1) Per-element data API, (2) Cross-browser CSS getters/setters, and (3) scrollTop/Left offset helpers. Keep these features in mind when making custom jQuery builds or porting tram to your library.</p>
<p>Available on npm: <code>npm install tram</code><br>Available on bower: <code>bower install tram</code> </p>
<p>File size:</p>
<ul>
<li>dev ~<code>45 kb</code></li>
<li>min ~<code>16 kb</code></li>
<li>gzip ~<code>4 kb</code></li>
</ul>
<h2 id="examples">Examples</h2>
<ul>
<li><a href="http://bkwld.github.io/tram/examples/basic-opacity.html">basic-opacity</a></li>
<li><a href="http://bkwld.github.io/tram/examples/scroll-top-left.html">scroll-top-left</a></li>
<li><a href="http://bkwld.github.io/tram/examples/sequencing.html">sequencing</a></li>
<li><a href="http://bkwld.github.io/tram/examples/modify-settings.html">modify-settings</a></li>
<li><a href="http://bkwld.github.io/tram/examples/to-from-auto.html">to-from-auto</a></li>
<li><a href="http://bkwld.github.io/tram/examples/transforms.html">transforms</a></li>
<li><a href="http://bkwld.github.io/tram/examples/wait-usage.html">wait-usage</a></li>
</ul>
<h2 id="how-it-works">How it works</h2>
<p>On first load, Tram will use feature detection to determine whether
the browser supports CSS transitions. If yes, Tram will manage styles
and trust the browser to handle the frame by frame animation.
If no, Tram will set styles on each frame, using its own tweening
engine powered by <a href="http://paulirish.com/2011/requestanimationframe-for-smart-animating/" title="requestAnimationFrame">requestAnimationFrame</a> and <a href="http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision" title="performance.now()">performance.now()</a>.</p>
<p><em>Please keep your arms and legs inside the tram at all times.</em></p>
<h3 id="basic-usage">Basic usage</h3>
<p>Tram can be loaded via AMD, CommonJS, browser globals, or all of the above (<a href="https://github.com/umdjs/umd">via UMD</a>).</p>
<pre><code class="lang-js"><span class="keyword">var</span> tram = window.tram;
<span class="comment">// or</span>
<span class="keyword">var</span> tram = <span class="keyword">require</span>(<span class="string">'tram'</span>);</code></pre>
<p>Before you add a transition to an element, you must first wrap it with the <code>tram()</code> method. This stores a Tram class instance in the element data, which is used for auto-stop and other state.</p>
<pre><code class="lang-js"><span class="function"><span class="title">tram</span><span class="params">(element)</span>;</code></pre>
<p>You may optionally save a reference to this instance, which may help performance for a large group of elements.</p>
<pre><code class="lang-js"><span class="keyword">var</span> myTram = tram(element); <span class="comment">// optional</span></code></pre>
<p>Each property must now be defined using the <code>add()</code> method. This should feel very familiar to CSS3 transition shorthand: <code>property-name duration easing-function delay</code></p>
<pre><code class="lang-js"><span class="function"><span class="title">tram</span><span class="params">(element)</span>.<span class="title">add</span><span class="params">('opacity <span class="number">500</span>ms ease-out')</span>;</code></pre>
<p>Once a transition is defined, it is stored in element data. You may override settings later, for example:</p>
<pre><code class="lang-js">tram(element).add(<span class="attribute">'opacity</span> <span class="number">2</span>s'); // changed duration <span class="keyword">to</span> <span class="number">2</span> seconds</code></pre>
<p>To begin a transition on your element, the <code>start()</code> method is used.</p>
<pre><code class="lang-js"><span class="function"><span class="title">tram</span><span class="params">(element)</span>.<span class="title">start</span><span class="params">(<span class="tuple">{ opacity: <span class="number">0.5</span> }</span>)</span>;</code></pre>
<p>If you'd like to listen for the transition end event, use <code>then()</code> and supply a function:</p>
<pre><code class="lang-js"><span class="function"><span class="title">tram</span><span class="params">(element)</span>
.<span class="title">start</span><span class="params">(<span class="tuple">{ opacity: <span class="number">0.5</span> }</span>)</span>
.<span class="title">then</span><span class="params">(function () <span class="tuple">{ console.<span class="function_name">log</span>('done!') }</span>);</code></pre>
<p>Sequencing is also available by using <code>then()</code>. For example:</p>
<pre><code class="lang-js"><span class="function"><span class="title">tram</span><span class="params">(element)</span>
.<span class="title">start</span><span class="params">(<span class="tuple">{ opacity: <span class="number">0.5</span> }</span>)</span>
.<span class="title">then</span><span class="params">(<span class="tuple">{ opacity: <span class="number">1</span> }</span>)</span>
.<span class="title">then</span><span class="params">(<span class="tuple">{ opacity: <span class="number">0</span> }</span>)</span>;</code></pre>
<p>Tram provides some virtual properties to help with CSS3 transforms.</p>
<pre><code class="lang-js">tram(element)
.add(<span class="string">'transform 1s ease-out-quint'</span>)
.start({ <span class="method">x:</span> <span class="number">100</span>, <span class="method">rotate:</span> <span class="number">45</span> }); // <span class="method">aka:</span> translateX(<span class="number">100</span>px) rotate(<span class="number">45</span>deg)</code></pre>
<p>If you need to set style values right away, use the <code>set()</code> method. This will stop any transitions, and immediately set the values.</p>
<pre><code class="lang-js"><span class="function"><span class="title">tram</span><span class="params">(element)</span>.<span class="title">set</span><span class="params">(<span class="tuple">{ x: <span class="number">0</span>, opacity: <span class="number">1</span> }</span>)</span>;</code></pre>
<p>Stopping a transition may be done using the <code>stop()</code> method. This also happens automatically whenever <code>start()</code> or <code>set()</code> are called.</p>
<pre><code class="lang-js">tram(element).stop(<span class="string">'opacity'</span>); <span class="comment">// specific property</span>
tram(element).stop({ opacity: <span class="keyword">true</span>, x: <span class="keyword">true</span> }); <span class="comment">// multiple properties</span>
tram(element).stop(); <span class="comment">// stops all property transitions</span></code></pre>
<p>That's about it. For more, check out the <a href="examples">examples</a> or refer to the docs below.</p>
<h2 id="methods">Methods</h2>
<p>TODO document each method</p>
<h2 id="properties">Properties</h2>
<p>Browser support for transitioning DOM properties is limited, so Tram attempts to cover the most common cross-browser properties, plus a few extras. This list was compiled using CSS animation specs <a href="http://oli.jp/2010/css-animatable-properties/" title="oli.jp">here</a> and <a href="http://www.w3.org/TR/css3-transitions/#properties-from-css-" title="w3.org">here</a>.</p>
<h3 id="supported-property-names-values">Supported property names / values</h3>
<pre><code class="lang-js">'color' <span class="comment">// color</span>
'background' <span class="comment">// color</span>
'outline-color' <span class="comment">// color</span>
'border-color' <span class="comment">// color</span>
'border-top-color' <span class="comment">// color</span>
'border-right-color' <span class="comment">// color</span>
'border-bottom-color' <span class="comment">// color</span>
'border-left-color' <span class="comment">// color</span>
'border-width' <span class="comment">// length</span>
'border-top-width' <span class="comment">// length</span>
'border-right-width' <span class="comment">// length</span>
'border-bottom-width' <span class="comment">// length</span>
'border-left-width' <span class="comment">// length</span>
'border-spacing' <span class="comment">// length</span>
'letter-spacing' <span class="comment">// length</span>
'margin' <span class="comment">// length</span>
'margin-top' <span class="comment">// length</span>
'margin-right' <span class="comment">// length</span>
'margin-bottom' <span class="comment">// length</span>
'margin-left' <span class="comment">// length</span>
'padding' <span class="comment">// length</span>
'padding-top' <span class="comment">// length</span>
'padding-right' <span class="comment">// length</span>
'padding-bottom' <span class="comment">// length</span>
'padding-left' <span class="comment">// length</span>
'outline-width' <span class="comment">// length</span>
'opacity' <span class="comment">// number</span>
'top' <span class="comment">// length, percentage</span>
'right' <span class="comment">// length, percentage</span>
'bottom' <span class="comment">// length, percentage</span>
'left' <span class="comment">// length, percentage</span>
'font-size' <span class="comment">// length, percentage</span>
'text-indent' <span class="comment">// length, percentage</span>
'word-spacing' <span class="comment">// length, percentage</span>
'width' <span class="comment">// length, percentage</span>
'<span class="built_in">min</span>-width' <span class="comment">// length, percentage</span>
'<span class="built_in">max</span>-width' <span class="comment">// length, percentage</span>
'height' <span class="comment">// length, percentage</span>
'<span class="built_in">min</span>-height' <span class="comment">// length, percentage</span>
'<span class="built_in">max</span>-height' <span class="comment">// length, percentage</span>
'line-height' <span class="comment">// number, length, percentage</span>
'transform' <span class="comment">// (see transform info below)</span>
'scroll-top' <span class="comment">// number (tween-only)</span>
'scroll-left' <span class="comment">// number (tween-only)</span>
<span class="comment">// TODO - planned support</span>
<span class="comment">// 'background-position' // [x, y] length, percentage</span>
<span class="comment">// 'transform-origin' // [x, y] length, percentage</span>
<span class="comment">// 'clip' // [x, y, w, h] rectangle</span>
<span class="comment">// 'crop' // [x, y, w, h] rectangle</span></code></pre>
<p><strong>Note:</strong> <code>dash-style</code> names are required for <code>.add()</code>, but other methods like <code>.start()</code> and <code>.stop()</code> may use <code>camelCase</code>.</p>
<h3 id="transforms">Transforms</h3>
<p>TODO describe transform shortcuts w/ examples</p>
<pre><code class="lang-js"><span class="string">'x'</span> <span class="comment">// length, percentage</span>
<span class="string">'y'</span> <span class="comment">// length, percentage</span>
<span class="string">'z'</span> <span class="comment">// length, percentage</span>
<span class="string">'rotate'</span> <span class="comment">// angle</span>
<span class="string">'rotateX'</span> <span class="comment">// angle</span>
<span class="string">'rotateY'</span> <span class="comment">// angle</span>
<span class="string">'rotateZ'</span> <span class="comment">// angle</span>
<span class="string">'scale'</span> <span class="comment">// number</span>
<span class="string">'scaleX'</span> <span class="comment">// number</span>
<span class="string">'scaleY'</span> <span class="comment">// number</span>
<span class="string">'scaleZ'</span> <span class="comment">// number</span>
<span class="string">'skew'</span> <span class="comment">// angle</span>
<span class="string">'skewX'</span> <span class="comment">// angle</span>
<span class="string">'skewY'</span> <span class="comment">// angle</span>
<span class="string">'perspective'</span> <span class="comment">// length</span></code></pre>
<h3 id="easings">Easings</h3>
<p>A useful site with demos of most of these is <a href="http://easings.net/">easings.net</a></p>
<pre><code class="lang-js">// Defaults
<span class="attribute">'ease</span>'
<span class="attribute">'ease</span>-<span class="keyword">in</span>'
<span class="attribute">'ease</span>-<span class="keyword">out</span>'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>'
<span class="attribute">'linear</span>'
// Quad
<span class="attribute">'ease</span>-<span class="keyword">in</span>-quad'
<span class="attribute">'ease</span>-<span class="keyword">out</span>-quad'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>-quad'
// Cubic
<span class="attribute">'ease</span>-<span class="keyword">in</span>-cubic'
<span class="attribute">'ease</span>-<span class="keyword">out</span>-cubic'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>-cubic'
// Quart
<span class="attribute">'ease</span>-<span class="keyword">in</span>-quart'
<span class="attribute">'ease</span>-<span class="keyword">out</span>-quart'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>-quart'
// Quint
<span class="attribute">'ease</span>-<span class="keyword">in</span>-quint'
<span class="attribute">'ease</span>-<span class="keyword">out</span>-quint'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>-quint'
// Sine
<span class="attribute">'ease</span>-<span class="keyword">in</span>-sine'
<span class="attribute">'ease</span>-<span class="keyword">out</span>-sine'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>-sine'
// Expo
<span class="attribute">'ease</span>-<span class="keyword">in</span>-expo'
<span class="attribute">'ease</span>-<span class="keyword">out</span>-expo'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>-expo'
// Circ
<span class="attribute">'ease</span>-<span class="keyword">in</span>-circ'
<span class="attribute">'ease</span>-<span class="keyword">out</span>-circ'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>-circ'
// Back
<span class="attribute">'ease</span>-<span class="keyword">in</span>-back'
<span class="attribute">'ease</span>-<span class="keyword">out</span>-back'
<span class="attribute">'ease</span>-<span class="keyword">in</span>-<span class="keyword">out</span>-back'</code></pre>
<h2 id="todo">TODO</h2>
<ul>
<li>Add .get(prop) method to return current value</li>
<li>Support array values for props like 'background-position'</li>
</ul>
<h2 id="contributing">Contributing</h2>
<ol>
<li><p>If you'd like to contribute to this project, please submit all pull requests to the <code>dev</code> branch. Any pull requests sent to <code>master</code> will be closed. This is mostly to offset the convenience of having various dist/* files available on the master branch.</p>
</li>
<li><p>Grunt CLI tools may be helpful. The following commands should start a watch script that concats source files on each save:<br>(from the root directory)<br><code>npm install grunt -g</code><br><code>grunt</code> </p>
</li>
<li><p>Once you're ready to send a pull request, please view <code>test/suite.html</code> in your browser to confirm that all tests are passing.</p>
</li>
</ol>
<h2 id="thanks">Thanks</h2>
<p>Special thanks to the following open source authors + libraries.</p>
<p>@ded - <a href="https://github.com/ded/morpheus">https://github.com/ded/morpheus</a><br>@rstacruz - <a href="https://github.com/rstacruz/jquery.transit">https://github.com/rstacruz/jquery.transit</a><br>@visionmedia - <a href="https://github.com/visionmedia/move.js">https://github.com/visionmedia/move.js</a><br>@jayferd - <a href="https://github.com/jayferd/pjs">https://github.com/jayferd/pjs</a> </p>
<h2 id="mit-license">MIT License</h2>
<p>This code may be freely distributed under the <a href="http://danro.mit-license.org/">MIT license</a>.</p>
<h3 id="terms-of-use-easing-equations">Terms Of Use - Easing Equations</h3>
<p>Open source under the <a href="http://www.opensource.org/licenses/bsd-license.php">BSD License</a>.</p>
<p>Copyright © 2001 Robert Penner
All rights reserved.</p>
<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p>
<ul>
<li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
<li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li>
<li>Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.</li>
</ul>
<p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
</body>
</html>