forked from malsup/cycle2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.cycle2.shuffle.js
62 lines (53 loc) · 2.03 KB
/
jquery.cycle2.shuffle.js
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
/*! shuffle transition plugin for Cycle2; version: 20121120 */
(function($) {
"use strict";
$.fn.cycle.transitions.shuffle = {
transition: function( opts, currEl, nextEl, fwd, callback ) {
$( nextEl ).show();
var width = opts.container.css( 'overflow', 'visible' ).width();
var speed = opts.speed / 2; // shuffle has 2 transitions
var element = fwd ? currEl : nextEl;
opts = opts.API.getSlideOpts( fwd ? opts.currSlide : opts.nextSlide );
var props1 = { left:-width, top:15 };
var props2 = opts.slideCss || { left:0, top:0 };
if ( opts.shuffleLeft !== undefined ) {
props1.left = props1.left + parseInt(opts.shuffleLeft, 10) || 0;
}
else if ( opts.shuffleRight !== undefined ) {
props1.left = width + parseInt(opts.shuffleRight, 10) || 0;
}
if ( opts.shuffleTop ) {
props1.top = opts.shuffleTop;
}
// transition slide in 3 steps: move, re-zindex, move
$( element )
.animate( props1, speed, opts.easeIn || opts.easing )
.queue( 'fx', $.proxy(reIndex, this))
.animate( props2, speed, opts.easeOut || opts.easing, callback );
function reIndex(nextFn) {
/*jshint validthis:true */
this.stack(opts, currEl, nextEl, fwd);
nextFn();
}
},
stack: function( opts, currEl, nextEl, fwd ) {
var i, z;
if (fwd) {
opts.API.stackSlides( nextEl, currEl, fwd );
// force curr slide to bottom of the stack
$(currEl).css( 'zIndex', 1 );
}
else {
z = 1;
for (i = opts.nextSlide - 1; i >= 0; i--) {
$(opts.slides[i]).css('zIndex', z++);
}
for (i = opts.slideCount - 1; i > opts.nextSlide; i--) {
$(opts.slides[i]).css('zIndex', z++);
}
$(nextEl).css( 'zIndex', opts.maxZ );
$(currEl).css( 'zIndex', opts.maxZ - 1 );
}
}
};
})(jQuery);