-
Notifications
You must be signed in to change notification settings - Fork 85
/
jquery.fractionslider.js
1281 lines (1073 loc) · 31.2 KB
/
jquery.fractionslider.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
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* jQuery Fraction Slider v1.0
* http://fractionslider.jacksbox.de
*
* Author: Mario Jäckle
* eMail: [email protected]
*
* Copyright 2013, jacksbox.design
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Special thanks to: Lietzi (https://github.com/lietzi) for contributing
*/
( function($) {
/** ************************* **/
/** Methods **/
/** ************************* **/
var slider = null, methods = {
init : function(option) {
// defaults & options
var options = $.extend({
'slideTransition' : 'none', // default slide transition
'slideTransitionSpeed' : 2000, // default slide transition
'slideEndAnimation' : true, // if set true, objects will transition out at slide end (before the slideTransition is called)
'position' : '0,0', // default position | should never be used
'transitionIn' : 'left', // default in - transition
'transitionOut' : 'left', // default out - transition
'fullWidth' : false, // transition over the full width of the window
'delay' : 0, // default delay for elements
'timeout' : 2000, // default timeout before switching slides
'speedIn' : 2500, // default in - transition speed
'speedOut' : 1000, // default out - transition speed
'easeIn' : 'easeOutExpo', // default easing in
'easeOut' : 'easeOutCubic', // default easing out
'controls' : false, // controls on/off
'pager' : false, // controls on/off
'autoChange' : true, // auto change slides
'pauseOnHover' : false, // Pauses slider on hover (current step will still be completed)
'backgroundAnimation' : false, // background animation
'backgroundElement' : null, // element to animate | default fractionSlider element
'backgroundX' : 500, // default x distance
'backgroundY' : 500, // default y distance
'backgroundSpeed' : 2500, // default background animation speed
'backgroundEase' : 'easeOutCubic', // default background animation easing
'responsive' : false, // activates the responsive slider
'increase' : false, // if set, slider is allowed to get bigger than basic dimensions
'dimensions' : '', // set basic dimension (width,height in px) for the responisve slider - the plugin with position elements with data-position relative to this dimensions (please see the documentation for more info),
'startCallback' : null,
'startNextSlideCallback' : null,
'stopCallback' : null,
'pauseCallback' : null,
'resumeCallback' : null,
'nextSlideCallback' : null,
'prevSlideCallback' : null,
'pagerCallback' : null
}, option);
return this.each(function() {
// ready for take-off
slider = new FractionSlider(this, options);
});
},
pause : function() {
slider.pause(true);
},
resume : function() {
slider.resume();
},
stop : function() {
slider.stop();
},
start : function() {
slider.start();
},
startNextSlide : function() {
slider.startNextSlide();
}
};
/** ************************* **/
/** SLDIER CLASS **/
/** ************************* **/
// here happens all the fun
var FractionSlider = function(element, options) {
var vars = {
init : true, // initialised the first time
running : false, // currently running
pause : false,
stop : false,
slideComplete : false, // current slide complete (needed for pause method)
stepComplete : false,
controlsActive : true, // controls pressed
currentSlide : 0, // current slide number
lastSlide : null, // last slide number (for anim out)
maxSlide : 0, // max slide number
currentStep : 0, // current step number
maxStep : 0, // max step number
currentObj : 0, // curent object number (in step)
maxObjs : 0, // max object number (in step)
finishedObjs : 0 // finsihed objects (in step)
},
// Here are Slide elements temporarily stored
temp = {
currentSlide : null, // current Slide
lastSlide : null, // last Slide (for anim out)
animationkey : 'none' // animation for slidechange
}, timeouts = [], fractionObjs = null,
// objs for current step
dX = null, dY = null;
$(element).wrapInner('<div class="fraction-slider" />');
var slider = $(element).find('.fraction-slider'), pager = null;
// the slider element
vars.maxSlide = slider.children('.slide').length - 1;
// some more needed vars
var sliderWidth = slider.width(), bodyWidth = $('body').width(), offsetX = 0;
if (options.fullWidth) {
offsetX = (bodyWidth - sliderWidth) / 2;
sliderWidth = bodyWidth;
}
var sliderHeight = slider.height();
init();
/** ************************* **/
/** INITIALIZE **/
/** ************************* **/
function init() {
// controls
if (options.controls) {
slider.append('<a href="#" class="prev"></a><a href="#" class="next" ></a>');
slider.find('.next').bind('click', function() {
return nextBtnPressed();
});
slider.find('.prev').bind('click', function() {
return prevBtnPressed();
});
}
if (options.pauseOnHover) {
slider.bind({
mouseenter: function(){ pause(false); },
mouseleave: function(){ resume(); }
});
}
// fullwidth setup
if (options.fullWidth) {
slider.css({
'overflow' : 'visible'
});
} else {
slider.css({
'overflow' : 'hidden'
});
}
if (options.pager) {
var customPager = (typeof options.pager !== 'boolean');
pager = (customPager) ? options.pager : $('<div class="fs-pager-wrapper"></div>');
if (!customPager) {
slider.append(pager);
}else{
pager.addClass('fs-custom-pager-wrapper');
}
}
slider.children('.slide').each(function(index) {
var slide = $(this);
slide.children().attr('rel', index).addClass('fs_obj');
slide.children('[data-fixed]').addClass('fs_fixed_obj');
// pager again
if (options.pager || customPager) {
var tempObj = $('<a rel="' + index + '" href="#"></a>').bind('click', function() {
return pagerPressed(this);
});
pager.append(tempObj);
}
});
if (options.pager) {
pager = $(pager).children('a');
}
// responisve
if (options.responsive) {
makeResponsive();
}
// remove spinner
if (slider.find('.fs_loader').length > 0) {
slider.find('.fs_loader').remove();
}
// all importent stuff is done, everybody has taken a shower, we can go
// starts the slider and the slide rotation
start();
}
/** ************************* **/
/** METHODES **/
/** ************************* **/
function start() {
vars.stop = false;
vars.pause = false;
vars.running = true;
cycle('slide');
methodeCallback(options.startCallback);
}
this.start = function() {// for method calls
start();
};
function startNextSlide() {
vars.stop = false;
vars.pause = false;
vars.running = true;
nextSlide();
methodeCallback(options.startNextSlideCallback);
}
this.startNextSlide = function() {// for method calls
startNextSlide();
};
// use with start or startNextSlide
function stop() {
vars.stop = true;
vars.running = false;
slider.find('.slide').stop(true, true);
slider.find('.fs_obj').stop(true, true).removeClass('fs-animation');
stopTimeouts(timeouts);
methodeCallback(options.stopCallback);
}
this.stop = function() {// for method calls
stop();
};
// use with resume
function pause(finish) {
vars.pause = true;
vars.running = false;
if(finish) {
slider.find('.fs-animation').finish(); // finish the current step
}
methodeCallback(options.pauseCallback);
}
this.pause = function() {// for method calls
pause(false);
};
// use with pause
function resume() {
vars.stop = false;
vars.pause = false;
vars.running = true;
if( vars.slideComplete ) {
cycle('slide');
} else if( vars.stepComplete ) {
cycle('step');
} else {
if (vars.finishedObjs < vars.maxObjs) {
// do nothing - elements are still animating
} else if (vars.currentStep < vars.maxStep) { // IS THIS STILL NEEDED?
cycle('step'); // IS THIS STILL NEEDED?
} else {
cycle('slide'); // IS THIS STILL NEEDED?
}
}
methodeCallback(options.resumeCallback );
}
this.resume = function() {// for method calls
resume();
};
function nextSlide() {
vars.lastSlide = vars.currentSlide;
vars.currentSlide += 1;
vars.stop = false;
vars.pause = false;
vars.running = true;
slideChangeControler();
methodeCallback(options.nextSlideCallback);
}
function prevSlide() {
vars.lastSlide = vars.currentSlide;
vars.currentSlide -= 1;
vars.stop = false;
vars.pause = false;
vars.running = true;
slideChangeControler();
methodeCallback(options.prevSlideCallback);
}
function targetSlide(slide) {
vars.lastSlide = vars.currentSlide;
vars.currentSlide = slide;
vars.stop = false;
vars.pause = false;
vars.running = true;
slideChangeControler();
methodeCallback(options.pagerCallback);
}
/** ************************* **/
/** CALLBACKS **/
/** ************************* **/
function methodeCallback(callback) {
$.isFunction( callback ) && callback.call( this, slider, vars.currentSlide, vars.lastSlide, vars.currentStep );
}
/** ************************* **/
/** PAGER & CONTROLS **/
/** ************************* **/
function pagerPressed(el) {
var target = parseInt($(el).attr('rel'));
if (target != vars.currentSlide) {
stop();
targetSlide(target);
}
return false;
}
function prevBtnPressed() {
stop();
prevSlide();
return false;
}
function nextBtnPressed() {
stop();
nextSlide();
return false;
}
/** ************************* **/
/** CYCLE CONTROLLER **/
/** ************************* **/
function cycle(type) {
if (!vars.pause && !vars.stop && vars.running) {
switch(type) {
case "slide":
vars.slideComplete = false;
slideRotation();
break;
case "step":
vars.stepComplete = false;
iterateSteps();
break;
case "obj":
iterateObjs();
break;
}
}
}
/** ************************* **/
/** SLIDES **/
/** ************************* **/
function slideRotation() {
var timeout = options.timeout;
// set timeout | first slide instant start
if (vars.init) {
vars.init = false;
slideChangeControler(true);
} else {
// timeout after slide is complete
timeouts.push(setTimeout(function() {
// stops the slider after first slide (only when slide count = 1)
if (vars.maxSlide == 0 && vars.running == true) {
// TODO: better solution!
} else {
vars.lastSlide = vars.currentSlide;
vars.currentSlide += 1;
slideChangeControler();
}
}, timeout));
}
}
function slideChangeControler(init) {
slider.find('.active-slide').removeClass('active-slide');
if (vars.currentSlide > vars.maxSlide) {
vars.currentSlide = 0;
}
if (vars.currentSlide < 0) {
vars.currentSlide = vars.maxSlide;
}
temp.currentSlide = slider.children('.slide:eq(' + vars.currentSlide + ')').addClass('active-slide');
if (temp.currentSlide.length == 0) {
vars.currentSlide = 0;
temp.currentSlide = slider.children('.slide:eq(' + vars.currentSlide + ')');
}
if (vars.lastSlide != null) {
if (vars.lastSlide < 0) {
vars.lastSlide = vars.maxSlide;
}
temp.lastSlide = slider.children('.slide:eq(' + vars.lastSlide + ')');
}
if (init) {
temp.animation = 'none';
} else {
temp.animation = temp.currentSlide.attr("data-in");
if (temp.animation == null) {
temp.animation = options.slideTransition;
}
}
if (options.slideEndAnimation && vars.lastSlide != null) {
objOut();
} else {
switch(temp.animation) {
case 'none':
startSlide();
endSlide();
break;
case 'scrollLeft':
startSlide();
endSlide();
break;
case 'scrollRight':
startSlide();
endSlide();
break;
case 'scrollTop':
startSlide();
endSlide();
break;
case 'scrollBottom':
startSlide();
endSlide();
break;
default:
startSlide();
break;
}
}
}
// starts a slide
function startSlide() {
if (options.backgroundAnimation) {
backgroundAnimation();
}
if (options.pager) {
pager.removeClass('active');
pager.eq(vars.currentSlide).addClass('active');
}
getStepsForSlide();
temp.currentSlide.children().hide();
vars.currentStep = 0;
vars.currentObj = 0;
vars.maxObjs = 0;
vars.finishedObjs = 0;
temp.currentSlide.children("[data-fixed]").show();
slideAnimationIn();
}
function startSlideComplete(slide) {
if (temp.lastSlide != null) {
temp.lastSlide.hide();
}
if (slide.hasClass('active-slide')) {
// starts the cycle for the current slide
cycle('step');
}
}
// ends a slide
function endSlide() {
if (temp.lastSlide == null) {
return;
}
if (temp.animation != 'none') {
slideAnimationOut();
}
}
function endSlideComplete() {
}
/** ************************* **/
/** STEPS **/
/** ************************* **/
// gets the maximum step for the current slide
function getStepsForSlide() {
var objs = temp.currentSlide.children(), maximum = 0;
objs.each(function() {
var value = parseFloat($(this).attr('data-step'));
maximum = (value > maximum) ? value : maximum;
});
vars.maxStep = maximum;
}
function iterateSteps() {
var objs;
if (vars.currentStep == 0) {
objs = temp.currentSlide.children('*:not([data-step]):not([data-fixed]), *[data-step="' + vars.currentStep + '"]:not([data-fixed])');
} else {
objs = temp.currentSlide.children('*[data-step="' + vars.currentStep + '"]:not([data-fixed])');
}
vars.maxObjs = objs.length;
fractionObjs = objs;
if (vars.maxObjs > 0) {
vars.currentObj = 0;
vars.finishedObjs = 0;
cycle('obj');
} else {
stepFinished();
}
}
function stepFinished() {
vars.stepComplete = true;
vars.currentStep += 1;
if (vars.currentStep > vars.maxStep) {
if (options.autoChange) {
vars.currentStep = 0;
vars.slideComplete = true;
cycle('slide');
}
return;
}
cycle('step');
}
/** ************************* **/
/** OBJECTS **/
/** ************************* **/
function iterateObjs() {
var obj = $(fractionObjs[vars.currentObj]);
obj.addClass('fs-animation');
var position = obj.attr("data-position"), transition = obj.attr("data-in"), delay = obj.attr("data-delay"), time = obj.attr('data-time'), easing = obj.attr('data-ease-in'),
// check for special options
special = obj.attr("data-special");
if (position == null) {
position = options.position.split(',');
} else {
position = position.split(',');
}
if (transition == null) {
transition = options.transitionIn;
}
if (delay == null) {
delay = options.delay;
}
if (easing == null) {
easing = options.easeIn;
}
objectAnimationIn(obj, position, transition, delay, time, easing, special);
vars.currentObj += 1;
if (vars.currentObj < vars.maxObjs) {
cycle('obj');
} else {
vars.currentObj = 0;
}
}
function objFinished(obj) {
obj.removeClass('fs-animation');
if (obj.attr('rel') == vars.currentSlide) {
vars.finishedObjs += 1;
if (vars.finishedObjs == vars.maxObjs) {
stepFinished();
}
}
}
function objOut() {
var objs = temp.lastSlide.children(':not([data-fixed])');
objs.each(function() {
var obj = $(this), position = obj.position(), transition = obj.attr("data-out"), easing = obj.attr("data-ease-out");
if (transition == null) {
transition = options.transitionOut;
}
if (easing == null) {
easing = options.easeOut;
}
objectAnimationOut(obj, position, transition, null, easing);
}).promise().done(function() {
endSlide();
startSlide();
});
}
/** ************************* **/
/** TRANSITIONS **/
/** ************************* **/
/** TRANSITION SLIDES **/
function slideAnimationIn() {
var slide = temp.currentSlide, cssStart = {}, cssEnd = {}, speed = options.slideTransitionSpeed, animation = temp.animation;
if (options.responsive) {
unit = '%';
} else {
unit = 'px';
}
switch(animation) {
case 'slideLeft':
cssStart.left = sliderWidth + unit;
cssStart.top = '0' + unit;
cssStart.display = 'block';
cssEnd.left = '0' + unit;
cssEnd.top = '0' + unit;
break;
case 'slideTop':
cssStart.left = '0' + unit;
cssStart.top = -sliderHeight + unit;
cssStart.display = 'block';
cssEnd.left = '0' + unit;
cssEnd.top = '0' + unit;
break;
case 'slideBottom':
cssStart.left = '0' + unit;
cssStart.top = sliderHeight + unit;
cssStart.display = 'block';
cssEnd.left = '0' + unit;
cssEnd.top = '0' + unit;
break;
case 'slideRight':
cssStart.left = -sliderWidth + unit;
cssStart.top = '0' + unit;
cssStart.display = 'block';
cssEnd.left = '0' + unit;
cssEnd.top = '0' + unit;
break;
case 'fade':
cssStart.left = '0' + unit;
cssStart.top = '0' + unit;
cssStart.display = 'block';
cssStart.opacity = 0;
cssEnd.opacity = 1;
break;
case 'none':
cssStart.left = '0' + unit;
cssStart.top = '0' + unit;
cssStart.display = 'block';
speed = 0;
break;
case 'scrollLeft':
cssStart.left = sliderWidth + unit;
cssStart.top = '0' + unit;
cssStart.display = 'block';
cssEnd.left = '0' + unit;
cssEnd.top = '0' + unit;
break;
case 'scrollTop':
cssStart.left = '0' + unit;
cssStart.top = -sliderHeight + unit;
cssStart.display = 'block';
cssEnd.left = '0' + unit;
cssEnd.top = '0' + unit;
break;
case 'scrollBottom':
cssStart.left = '0' + unit;
cssStart.top = sliderHeight + unit;
cssStart.display = 'block';
cssEnd.left = '0' + unit;
cssEnd.top = '0' + unit;
break;
case 'scrollRight':
cssStart.left = -sliderWidth + unit;
cssStart.top = '0' + unit;
cssStart.display = 'block';
cssEnd.left = '0' + unit;
cssEnd.top = '0' + unit;
break;
}
slide.css(cssStart).animate(cssEnd, speed, 'linear', function() {
startSlideComplete(slide);
});
}
function slideAnimationOut() {
var cssStart = {}, cssEnd = {}, speed = options.slideTransitionSpeed, unit = null, animation = temp.animation;
if (options.responsive) {
unit = '%';
} else {
unit = 'px';
}
switch(animation) {
// case 'none':
// cssStart.display = 'none';
// speed = 0
// break;
case 'scrollLeft':
cssEnd.left = -sliderWidth + unit;
cssEnd.top = '0' + unit;
break;
case 'scrollTop':
cssEnd.left = '0' + unit;
cssEnd.top = sliderHeight + unit;
break;
case 'scrollBottom':
cssEnd.left = '0' + unit;
cssEnd.top = -sliderHeight + unit;
break;
case 'scrollRight':
cssEnd.left = sliderWidth + unit;
cssEnd.top = '0' + unit;
break;
default:
speed = 0;
break;
}
temp.lastSlide.animate(cssEnd, speed, 'linear', function() {
endSlideComplete();
});
}
/** IN TRANSITION OBJECTS **/
function objectAnimationIn(obj, position, transition, delay, time, easing, special) {
var cssStart = {}, cssEnd = {}, speed = options.speedIn, unit = null;
if (options.responsive) {
unit = '%';
} else {
unit = 'px';
}
// #time
if (time != null && time != "") {
speed = time - delay;
}
cssStart.opacity = 1;
// set start position
switch(transition) {
case 'left':
cssStart.top = position[0];
cssStart.left = sliderWidth;
break;
case 'bottomLeft':
cssStart.top = sliderHeight;
cssStart.left = sliderWidth;
break;
case 'topLeft':
cssStart.top = obj.outerHeight() * -1;
cssStart.left = sliderWidth;
break;
case 'top':
cssStart.top = obj.outerHeight() * -1;
cssStart.left = position[1];
break;
case 'bottom':
cssStart.top = sliderHeight;
cssStart.left = position[1];
break;
case 'right':
cssStart.top = position[0];
cssStart.left = -offsetX - obj.outerWidth();
break;
case 'bottomRight':
cssStart.top = sliderHeight;
cssStart.left = -offsetX - obj.outerWidth();
break;
case 'topRight':
cssStart.top = obj.outerHeight() * -1;
cssStart.left = -offsetX - obj.outerWidth();
break;
case 'fade':
cssStart.top = position[0];
cssStart.left = position[1];
cssStart.opacity = 0;
cssEnd.opacity = 1;
break;
case 'none':
cssStart.top = position[0];
cssStart.left = position[1];
cssStart.display = 'none';
speed = 0;
break;
}
// set target position
cssEnd.top = position[0];
cssEnd.left = position[1];
// sets the right unit
cssEnd.left = cssEnd.left + unit;
cssEnd.top = cssEnd.top + unit;
cssStart.left = cssStart.left + unit;
cssStart.top = cssStart.top + unit;
// set the delay
timeouts.push(setTimeout(function() {
// for special=cylce
if (special == 'cycle' && obj.attr('rel') == vars.currentSlide) {
var tmp = obj.prev();
if (tmp.length > 0) {
var tmpPosition = $(tmp).attr('data-position').split(',');
tmpPosition = {
'top' : tmpPosition[0],
'left' : tmpPosition[1]
};
var tmpTransition = $(tmp).attr('data-out');
if (tmpTransition == null) {
tmpTransition = options.transitionOut;
}
objectAnimationOut(tmp, tmpPosition, tmpTransition, speed);
}
}
// animate
obj.css(cssStart).show().animate(cssEnd, speed, easing, function() {
objFinished(obj);
}).addClass('fs_obj_active');
}, delay));
}
/** OUT TRANSITION OBJECTS **/
function objectAnimationOut(obj, position, transition, speed, easing) {
var cssStart = {}, cssEnd = {}, unit = null;
speed = options.speedOut;
if (options.responsive) {
unit = '%';
} else {
unit = 'px';
}
var w = obj.outerWidth(), h = obj.outerHeight();
if (options.responsive) {
w = pixelToPercent(w, dX);
h = pixelToPercent(h, dY);
}
// set target position
switch(transition) {
case 'left':
cssEnd.left = -offsetX - 100 - w;
break;
case 'bottomLeft':
cssEnd.top = sliderHeight;
cssEnd.left = -offsetX - 100 - w;
break;
case 'topLeft':
cssEnd.top = -h;
cssEnd.left = -offsetX - 100 - w;
break;
case 'top':
cssEnd.top = -h;
break;
case 'bottom':
cssEnd.top = sliderHeight;
break;
case 'right':
cssEnd.left = sliderWidth;
break;
case 'bottomRight':
cssEnd.top = sliderHeight;
cssEnd.left = sliderWidth;
break;
case 'topRight':
cssEnd.top = -h;
cssEnd.left = sliderWidth;
break;
case 'fade':
cssStart.opacity = 1;
cssEnd.opacity = 0;
break;
case 'hide':
cssEnd.display = 'none';
speed = 0;
break;
default:
cssEnd.display = 'none';
speed = 0;
break;
}
if ( typeof cssEnd.top != 'undefined') {
// substracts the px
if (cssEnd.top.toString().indexOf('px') > 0) {
cssEnd.top = cssEnd.top.substring(0, cssEnd.top.length - 2);
if (options.responsive) {
cssEnd.top = pixelToPercent(cssEnd.top, dY);
}
}
}
if ( typeof cssEnd.left != 'undefined') {
if (cssEnd.left.toString().indexOf('px') > 0) {
cssEnd.left = cssEnd.left.substring(0, cssEnd.left.length - 2);
if (options.responsive) {
cssEnd.left = pixelToPercent(cssEnd.left, dX);
}
}
}
// sets the right unit
cssEnd.left = cssEnd.left + unit;
cssEnd.top = cssEnd.top + unit;
// animation
obj.css(cssStart).animate(cssEnd, speed, easing, function() {
obj.hide();
}).removeClass('fs_obj_active');
}
function backgroundAnimation() {