Download
User Rating: 4.4/5 ( 1 votes)
snabbt.js is a minimalistic javascript animation library. It focuses on moving things around. It will translate, rotate, scale, skew and resize your elements. By including matrix multiplication operations, transforms can be combined in any way you want. The end result is then set via CSS3 transform matrices.
snabbt.js is built to be fast. It will only animate things that modern browsers can animate cheaply: transforms and opacity. The goal is to make a library that will let the user make smooth animations without needing to know too much about browser rendering.
Note: For convenience, width and height are animatable too, but beware since they may cause page reflows and slow down your animations.
Limitations
-
All transforms work on pixels or radians. Any unit conversion has to be done beforehand.
-
No abritrary property animations, e.g. colors, padding, margin or line height animations.
-
For performance reasons, snabbt.js never queries the DOM. This means that in some cases you need to store end transforms yourself.
Source: daniel-lundin.github.io
1. INCLUDE JS FILES
<script src="jquery-2.1.1.min.js"></script>
<script src="snabbt.min.js"></script>
2. HTML
<button id="usage-example-execute">Run example</button>
3. JAVASCRIPT
$('#usage-example-execute').click(function() {
$('#usage-example-execute').snabbt({
position: [100, 0, 0],
rotation: [0, 0, Math.PI],
duration: 1000,
delay: 100,
easing: 'ease'
});
});
4. MATRIX API
The following functions represents the Matrix API:
-
snabbtjs.ident() - Returns the identity matrix
-
snabbtjs.trans(x, y, z) - Returns a translation matrix
-
snabbtjs.rotX(radians) - Returns a rotation around the x-axis
-
snabbtjs.rotY(radians) - Returns a rotation around the y-axis
-
snabbtjs.rotZ(radians) - Returns a rotation around the z-axis
-
snabbtjs.scale(x, y) - Returns a scaling matrix
-
snabbtjs.skew(ax, ay) - Returns a skew matrix
-
snabbtjs.mult(A, B) - Returns the matrix multiplication product of A * B
5. ANIMATION CONFIGURATION
The following parameters can be set on the configuration object:
Parameter |
Type |
Default |
Description |
position |
Array(3) |
[0, 0, 0] |
Pixel offsets in each x-, y- and z-direction |
rotation |
Array(3) |
[0, 0, 0] |
Rotation in radians in x-, y- and z-direction |
scale |
Array(2) |
[1, 1] |
Scale in x- and y-direction |
rotation_post |
Array(3) |
[0, 0, 0] |
Rotation applied after position and rotation |
width |
Scalar |
Unchanged |
Element width in pixels |
height |
Scalar |
Unchanged |
Element height in pixels |
opacity |
Scalar |
1 |
Element opacity(0 - 1) |
duration |
Scalar |
500 |
Animation duration in milliseconds |
delay |
Scalar |
0 |
Delay before the animation is started in milliseconds |
loop |
Scalar |
0 |
Number of times to repeat the animation |
callback |
function |
undefined |
Function to be called when animation is completed |
A from_xxx can be set on most properties:
Parameter |
Type |
Default |
from_position |
Array(3) |
[0, 0, 0] or previous end state |
from_rotation |
Array(3) |
[0, 0, 0] or previous end state |
from_scale |
Array(2) |
[1, 1] or previous end state |
from_rotation_post |
Array(3) |
[0, 0, 0] or previous end state |
from_width |
Scalar |
Previous end state width |
from_height |
Scalar |
Previous end state height |
from_opacity |
Scalar |
Previous end state opacity |