jquery.anythingslider.fx.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * AnythingSlider Slide FX 1.5.7 for AnythingSlider v1.7.11+
  3. * By Rob Garrison (aka Mottie & Fudgey)
  4. * Dual licensed under the MIT and GPL licenses.
  5. */
  6. (function($) {
  7. $.fn.anythingSliderFx = function(effects, options){
  8. // variable sizes shouldn't matter - it's just to get an idea to get the elements out of view
  9. var wrap = $(this).closest('.anythingSlider'),
  10. sliderWidth = wrap.width(),
  11. sliderHeight = wrap.height(),
  12. getBaseFx = function(s){
  13. var size = s, size2;
  14. // allow for start and end sizes/dimensions
  15. if (s && typeof s === 'string' && s.indexOf(',') > 0) {
  16. s = s.split(',');
  17. size = $.trim(s[0]); size2 = $.trim(s[1]);
  18. }
  19. return {
  20. // 'name' : [{ inFx: {effects}, { outFx: {effects} }, selector: []]
  21. 'top' : [{ inFx: { top: 0 }, outFx: { top: '-' + (size || sliderHeight) } }],
  22. 'bottom' : [{ inFx: { top: 0 }, outFx: { top: (size || sliderHeight) } }],
  23. 'left' : [{ inFx: { left: 0 }, outFx: { left: '-' + (size || sliderWidth) } }],
  24. 'right' : [{ inFx: { left: 0 }, outFx: { left: (size || sliderWidth) } }],
  25. 'fade' : [{ inFx: { opacity: size || 1 }, outFx: { opacity: 0 } }],
  26. 'expand' : [{ inFx: { width: size2 || '100%', height: size2 || '100%', top: '0%', left: '0%' } , outFx: { width: (size || '10%'), height: (size || '10%'), top: '50%', left: '50%' } }],
  27. 'grow' : [{ inFx: { top: 0, fontSize: size || '16px', opacity : 1 }, outFx: { top: '-200px', fontSize: size2 || '80px', opacity: 0 } }],
  28. 'listLR' : [{ inFx: { left: 0, opacity: 1 }, outFx: [{ left: (size || sliderWidth), opacity: 0 }, { left: '-' + (size || sliderWidth), opacity: 0 }], selector: [':odd', ':even'] }],
  29. 'listRL' : [{ inFx: { left: 0, opacity: 1 }, outFx: [{ left: (size || sliderWidth), opacity: 0 }, { left: '-' + (size || sliderWidth), opacity: 0 }], selector: [':even', ':odd'] }],
  30. 'caption-Top' : [{ inFx: { top: 0, opacity: 0.8 }, outFx: { top: ( '-' + size || -50 ), opacity: 0 } }],
  31. 'caption-Right' : [{ inFx: { right: 0, opacity: 0.8 }, outFx: { right: ( '-' + size || -150 ), opacity: 0 } }],
  32. 'caption-Bottom' : [{ inFx: { bottom: 0, opacity: 0.8 }, outFx: { bottom: ( '-' + size || -50 ), opacity: 0 } }],
  33. 'caption-Left' : [{ inFx: { left: 0, opacity: 0.8 }, outFx: { left: ( '-' + size || -150 ), opacity: 0 } }]
  34. };
  35. };
  36. return this.each(function(){
  37. $(this).data('AnythingSlider').fx = effects; // store fx list to allow dynamic modification
  38. var defaults = $.extend({
  39. easing : 'swing', // Default FX easing
  40. timeIn : 400, // Default time for in FX animation
  41. timeOut : 350, // Default time for out FX animation - when using predefined FX, this number gets divided by 2
  42. stopRepeat : false, // stops repeating FX animation when clicking on the same navigation tab
  43. outFxBind : 'slide_init', // When outFx animations are called
  44. inFxBind : 'slide_complete' // When inFx animations are called
  45. }, options),
  46. baseFx = getBaseFx(), // get base FX with standard sizes
  47. // Animate FX
  48. animateFx = function(el, opt, isOut, time){
  49. if (el.length === 0 || typeof opt === 'undefined') { return; } // no fx
  50. var o = opt[0] || opt,
  51. s = o[1] || '',
  52. // time needs to be a number, not a string
  53. t = time || parseInt( ((s === '') ? o.duration : o[0].duration), 10);
  54. if (isOut) {
  55. // don't change caption position from absolute
  56. if (el.css('position') !== 'absolute') { el.css({ position : 'relative' }); }
  57. el.stop();
  58. // multiple selectors for out animation
  59. if (s !== ''){
  60. el.filter(opt[1][0]).animate(o[0], { queue : false, duration : t, easing : o[0].easing });
  61. el.filter(opt[1][1]).animate(s, { queue : true, duration : t, easing : o[0].easing });
  62. return;
  63. }
  64. }
  65. // animation for no extra selectors
  66. el.animate(o, { queue : true, duration : t, easing : o.easing });
  67. },
  68. // Extract FX
  69. getFx = function(opts, isOut){
  70. // example: '.textSlide h3' : [ 'top fade', '200px' '500', 'easeOutBounce' ],
  71. var tmp, bfx2,
  72. ex = (isOut) ? 'outFx' : 'inFx', // object key
  73. bfx = {}, // base effects
  74. time = (isOut) ? defaults.timeOut : defaults.timeIn, // default duration settings
  75. // split & process multiple built-in effects (e.g. 'top fade')
  76. fx = $.trim(opts[0].replace(/\s+/g,' ')).split(' ');
  77. // look for multiple selectors in the Out effects
  78. if (isOut && fx.length === 1 && baseFx.hasOwnProperty(fx) && typeof (baseFx[fx][0].selector) !== 'undefined') {
  79. bfx2 = baseFx[fx][0].outFx;
  80. // add time and easing to first set, the animation will use it for both
  81. bfx2[0].duration = opts[2] || defaults.timeOut;
  82. bfx2[0].easing = opts[3] || defaults.easing;
  83. return [bfx2, baseFx[fx][0].selector || [] ];
  84. }
  85. // combine base effects
  86. $.each(fx, function(i,f){
  87. // check if built-in effect exists
  88. if (baseFx.hasOwnProperty(f)) {
  89. var t = typeof opts[1] === 'undefined' || opts[1] === '',
  90. // if size option is defined, get new base fx
  91. tmp = (t) ? baseFx : getBaseFx(opts[1]);
  92. $.extend(true, bfx, tmp[f][0][ex]);
  93. t = opts[2] || bfx.duration || time; // user set time || built-in time || default time set above
  94. bfx.duration = (isOut) ? t/2 : t; // out animation time is 1/2 of in time for predefined fx only
  95. bfx.easing = isNaN(opts[3]) ? opts[3] || defaults.easing : opts[4] || defaults.easing;
  96. }
  97. });
  98. return [bfx];
  99. },
  100. base = $(this)
  101. // bind events for "OUT" effects - occur when leaving a page
  102. .bind(defaults.outFxBind, function(e, slider){
  103. if (defaults.stopRepeat && slider.$lastPage[0] === slider.$targetPage[0]) { return; }
  104. var el, elOut, time, page = slider.$lastPage.add( slider.$items.eq(slider.exactPage) ).add( slider.$targetPage ),
  105. FX = slider.fx; // allow dynamically added FX
  106. if (slider.exactPage === 0) { page = page.add( slider.$items.eq( slider.pages ) ); } // add last (non-cloned) page if on first
  107. if (slider.options.animationTime < defaults.timeOut) {
  108. time = slider.options.animationTime || defaults.timeOut;
  109. }
  110. page = page.find('*').andSelf(); // include the panel in the selectors
  111. for (el in FX) {
  112. if (el === 'outFx') {
  113. // process "out" custom effects
  114. for (elOut in FX.outFx) {
  115. // animate current/last slide, unless it's a clone, then effect the original
  116. if (page.filter(elOut).length) { animateFx( page.filter(elOut), FX.outFx[elOut], true); }
  117. }
  118. } else if (el !== 'inFx') {
  119. // Use built-in effects
  120. if ($.isArray(FX[el]) && page.filter(el).length) {
  121. animateFx( page.filter(el), getFx(FX[el],true), true, time);
  122. }
  123. }
  124. }
  125. })
  126. // bind events for "IN" effects - occurs on target page
  127. .bind(defaults.inFxBind, function(e, slider){
  128. if (defaults.stopRepeat && slider.$lastPage[0] === slider.$targetPage[0]) { return; }
  129. var el, elIn, page = slider.$currentPage.add( slider.$items.eq(slider.exactPage) ),
  130. FX = slider.fx; // allow dynamically added FX
  131. page = page.find('*').andSelf(); // include the panel in the selectors
  132. for (el in FX) {
  133. if (el === 'inFx') {
  134. // process "in" custom effects
  135. for (elIn in FX.inFx) {
  136. // animate current page
  137. if (page.filter(elIn).length) { animateFx( page.filter(elIn), FX.inFx[elIn], false); }
  138. }
  139. // Use built-in effects
  140. } else if (el !== 'outFx' && $.isArray(FX[el]) && page.filter(el).length) {
  141. animateFx( page.filter(el), getFx(FX[el],false), false);
  142. }
  143. }
  144. })
  145. .data('AnythingSlider');
  146. // call gotoPage to trigger intro animation
  147. $(window).load(function(){ base.gotoPage(base.currentPage, base.playing); });
  148. });
  149. };
  150. })(jQuery);