vladkras

eaSlyder ver. 0.2

Jun 21st, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // eaSlyder ver. 0.2
  2. (function($) {
  3.     $.fn.eaSlyder = function(options) {
  4.         var $images = this.find('img'), total = $images.length, cur = 0, silderWidth = this.width();
  5.         var settings = {
  6.             'duration':4000,
  7.             'method':'fade'
  8.         };
  9.         if (typeof options === 'object') var settings = $.extend(settings, options);
  10.         else if (options) duration = options || 4000;
  11.         this.css({'overflow': 'hidden','position': 'relative'});
  12.         $images.css('height',this.height()+'px');
  13.             switch (settings['method']) {
  14.                 case 'fade':
  15.                     $images.each(function(index) {
  16.                         if (index) $(this).hide();
  17.                     });  
  18.                     setInterval(function() {
  19.                         $images.eq(cur).fadeOut(function() {
  20.                             cur = (cur == total -1) ? 0 : cur+1;
  21.                             $images.eq(cur).fadeIn();
  22.                         });            
  23.                     }, settings['duration']);
  24.                 break;
  25.                 case 'moveLeft':
  26.                     $images.each(function(index) {
  27.                         if (index) $(this).css({'position':'absolute','opacity':'0'});
  28.                         else $(this).css({'position':'absolute','left':'0'});
  29.                     });
  30.                     setInterval(function() {
  31.                         var silderWidth = $images.eq(cur).parent().width();
  32.                         $images.eq(cur).animate({
  33.                             opacity: 0,
  34.                             left: '-='+(silderWidth/2)
  35.                         },1000);
  36.                             cur = (cur == total-1) ? 0 : cur+1;
  37.                             $images.eq(cur).css('left',($images.eq(cur).width())+'px').animate({
  38.                                 opacity: 1,
  39.                                 left: (silderWidth/2-$images.eq(cur).width()/2)+'px'
  40.                             },1000);            
  41.                     }, settings['duration']);
  42.                 break;
  43.             }
  44.         return this;
  45.         }
  46. })(jQuery);
  47.  
  48. $(document).ready(function() {
  49.     $('#fade').eaSlyder({'method':'moveLeft'});
  50. });
Advertisement
Add Comment
Please, Sign In to add comment