Skip to content

Commit 3a76851

Browse files
author
daniel-lundin
committed
Add value feeding documentation
1 parent ebbe351 commit 3a76851

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

docs/docs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ $(function() {
8787
};
8888

8989

90+
// Value feed example
91+
$("#value-feed-example").on('click', function() {
92+
$("#value-feed-example").snabbt({
93+
value_feeder: function(i) {
94+
var y = 50*Math.sin(i*4*Math.PI);
95+
var x = Math.sin(i*Math.PI);
96+
return snabbtjs.mult(snabbtjs.scale(1+x, 1+x), snabbtjs.trans(x*400, y, 0));
97+
},
98+
duration: 1000,
99+
});
100+
});
101+
102+
103+
90104
// Scroll spy
91105
var navtop = $("#navbar").offset().top;
92106
var $docked_navbar = $("#docked-navbar");

docs/index.html

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,38 @@ <h3>Spring physics</h3>
183183
</ul>
184184
</section>
185185
<section id="advanced">
186-
<h2>Advanced concepts</h2>
187-
<p>This section describes some of the more advanced usages.</p>
188-
189-
<h3>Value feeding</h3>
190-
<p>The animation object is very simple to work with but has it limitations. Sometimes you want to do the transforms in an other order.</p>
191-
</section>
192-
<footer>
193-
Made by Daniel Lundin
194-
</footer>
186+
<h2>Advanced concepts</h2>
187+
<p>This section describes some of the more advanced usages.</p>
188+
189+
<h3>Value feeding</h3>
190+
<p>The animation object is very simple to work with but has it limitations. Sometimes you want to do the transforms in another order. This is where value feeding comes handy. The <em>value_feeder</em> expects a function that takes one parameter which will progress from 0 to 1. Every time it is called you should return a snabbtjs.matrix representing the current transform.</p>
191+
<h4>Example:</h4>
192+
<pre><code>snabbt(element, {
193+
value_feeder: function(i) {
194+
var y = 50*Math.sin(i*4*Math.PI);
195+
var x = Math.sin(i*Math.PI);
196+
return snabbtjs.mult(snabbtjs.scale(1+x, 1+x), snabbtjs.trans(x*400, y, 0));
197+
},
198+
duration: 1000,
199+
easing: 'cos'
200+
});</code></pre>
201+
<button id="value-feed-example" class="button-primary">Run example</button>
202+
<h4>Matrix API</h4>
203+
The following function represents the Matrix API:
204+
<ul>
205+
<li><strong>snabbtjs.ident()</strong> - Returns the identity matrix</li>
206+
<li><strong>snabbtjs.trans(x, y, z)</strong> - Returns a translation matrix</li>
207+
<li><strong>snabbtjs.rotX(radians)</strong> - Returns a rotation around the x-axis</li>
208+
<li><strong>snabbtjs.rotY(radians)</strong> - Returns a rotation around the y-axis</li>
209+
<li><strong>snabbtjs.rotZ(radians)</strong> - Returns a rotation around the z-axis</li>
210+
<li><strong>snabbtjs.scale(x, y)</strong> - Returns a scaling matrix</li>
211+
<li><strong>snabbtjs.skew(ax, ay)</strong> - Returns a skew matrix</li>
212+
<li><strong>snabbtjs.mult(A, B)</strong> - Returns the matrix multiplication product of A * B</li>
213+
</ul>
214+
</section>
215+
<footer>
216+
Made by Daniel Lundin
217+
</footer>
195218

196219
<script src="jquery-2.1.1.min.js"></script>
197220
<script src="snabbt.min.js"></script>

0 commit comments

Comments
 (0)