Skip to content

Commit 8e9f1ef

Browse files
author
daniel-lundin
committed
Added sequencing
1 parent 5aa1c6a commit 8e9f1ef

File tree

7 files changed

+106
-39
lines changed

7 files changed

+106
-39
lines changed

docs/css/custom.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ footer {
179179
transform: rotateY(-180deg);
180180
}
181181

182+
.sequence-example {
183+
display: inline-block;
184+
width: 50px;
185+
height: 50px;
186+
background: brown;
187+
}
182188

183189
.multi-container {
184190
position: relative;

docs/docs.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,27 @@ $(function() {
137137
});
138138
});
139139

140+
// Sequence example
141+
$('#sequence-element-example').on('click', function() {
142+
console.log('click');
143+
var elementOne = document.getElementById('sequence-one');
144+
var elementTwo = document.getElementById('sequence-two');
145+
snabbt.sequence([
146+
[elementTwo, {
147+
position: [100, 0, 0],
148+
}],
149+
[elementOne, {
150+
position: [100, 0, 0],
151+
}],
152+
[elementOne, {
153+
position: [0, 0, 0],
154+
}],
155+
[elementTwo, {
156+
position: [0, 0, 0],
157+
}],
158+
]
159+
);
160+
});
140161
// Value feed example
141162
$('#value-feed-example').on('click', function() {
142163
$('#value-feed-example').snabbt({

docs/index.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ <h3><i class="fa fa-rocket"></i>Fast</h3>
6868
</div>
6969
<div class="four columns">
7070
<h3><i class="fa fa-paper-plane"></i>Light</h3>
71-
<p> ~4kb minified and gzipped</p>
71+
<p> ~5kb minified and gzipped</p>
7272
</div>
7373
<div class="four columns">
7474
<h3><i class="fa fa-user"></i>Simple</h3>
@@ -258,6 +258,29 @@ <h3>Life cycle events</h3>
258258
<h2>Advanced concepts</h2>
259259
<p>This section describes some of the more advanced usages.</p>
260260

261+
<h3>Sequence</h3>
262+
<p>Chaining is convenient when animating a single element or group of elements in multiple steps. However, if you want to trigger animations on a different set of element once one animation is completed you often end up with a lot of callbacks. This is where sequencing comes into play. <em>snabbt.sequence</em> is a function call that allows you to specify an array of animations that should run in sequence.</p>
263+
<pre><code class="javascript">snabbt.sequence([
264+
[elementTwo, {
265+
position: [100, 0, 0],
266+
}],
267+
[elementOne, {
268+
position: [100, 0, 0],
269+
}],
270+
[elementOne, {
271+
position: [0, 0, 0],
272+
}],
273+
[elementTwo, {
274+
position: [0, 0, 0],
275+
}],
276+
]
277+
);</code></pre>
278+
<button id="sequence-element-example" class="button-primary extra-top-margin">Run example</button>
279+
<div>
280+
<div id="sequence-one" class="sequence-example"></div>
281+
<div id="sequence-two" class="sequence-example"></div>
282+
</div>
283+
261284
<h3>Value feeding</h3>
262285
<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>valueFeeder</em> parameter expects a function that takes two parameters, one which will progress from 0 to 1 and an identity matrix that you can modify. The function will be called every frame and should return a matrix(see <a href="#matrix">Matrix API</a>) representing the current transform.</p>
263286
<pre><code class="javascript">snabbt(element, {

docs/snabbt.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snabbt.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ module.exports = Engine;
530530
'use strict';
531531
/* global window */
532532

533+
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
534+
533535
var Engine = require('./engine.js');
534536
var preprocessOptions = require('./properties.js').preprocessOptions;
535537
var utils = require('./utils.js');
@@ -583,27 +585,42 @@ function snabbt(elements, arg2, arg3) {
583585
return aggregateChainer;
584586
}
585587

586-
//if (typeof window !== 'undefined') {
587-
// window.snabbt = function(element, arg2, arg3) {
588-
// return snabbt(element, arg2, arg3);
589-
// };
590-
// window.snabbt.createMatrix = createMatrix;
591-
// window.snabbt.setElementTransform = updateElementTransform;
592-
//
593-
// if (window.jQuery) {
594-
// (function ($) {
595-
// $.fn.snabbt = function(arg1, arg2) {
596-
// return snabbt(this.get(), arg1, arg2);
597-
// };
598-
// })(window.jQuery);
599-
// }
600-
//} else {
601-
602588
module.exports = function (element, arg2, arg3) {
603589
return snabbt(element, arg2, arg3);
604590
};
605591
module.exports.createMatrix = createMatrix;
606592
module.exports.setElementTransform = updateElementTransform;
593+
module.exports.sequence = function (queue) {
594+
var i = 0;
595+
596+
var next = function next() {
597+
++i;
598+
if (i > queue.length - 1) return;
599+
600+
var _queue$i = _slicedToArray(queue[i], 2);
601+
602+
var element = _queue$i[0];
603+
var options = _queue$i[1];
604+
605+
var previousAllDone = options.allDone;
606+
options.allDone = previousAllDone ? function () {
607+
previousAllDone();next();
608+
} : next;
609+
snabbt(element, options);
610+
};
611+
612+
var _queue$0 = _slicedToArray(queue[0], 2);
613+
614+
var element = _queue$0[0];
615+
var options = _queue$0[1];
616+
617+
var previousAllDone = options.allDone;
618+
options.allDone = previousAllDone ? function () {
619+
previousAllDone();next();
620+
} : next;
621+
622+
snabbt(element, options);
623+
};
607624

608625
if (typeof window !== 'undefined' && window.jQuery) {
609626
(function ($) {
@@ -613,8 +630,6 @@ if (typeof window !== 'undefined' && window.jQuery) {
613630
})(window.jQuery);
614631
}
615632

616-
//}
617-
618633
Engine.init();
619634

620635
},{"./engine.js":3,"./matrix.js":5,"./properties.js":6,"./utils.js":9}],5:[function(require,module,exports){

0 commit comments

Comments
 (0)