Advertisement
AlenaLP

Fade

Apr 1st, 2015
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.31 KB | None | 0 0
  1. <script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  2. <script type='text/javascript'>
  3. (function($){
  4.   $.fn.list_ticker = function(options){
  5.    
  6.     var defaults = {
  7.       speed:4000,
  8.    effect:'slide',
  9.    run_once:false
  10.     };
  11.    
  12.     var options = $.extend(defaults, options);
  13.    
  14.     return this.each(function(){
  15.      
  16.       var obj = $(this);
  17.       var list = obj.children();
  18.       var count = list.length - 1;
  19.  
  20.       list.not(':first').hide();
  21.      
  22.       var interval = setInterval(function(){
  23.        
  24.         list = obj.children();
  25.         list.not(':first').hide();
  26.        
  27.         var first_li = list.eq(0)
  28.         var second_li = list.eq(1)
  29.  
  30.   if(options.effect == 'slide'){
  31.    first_li.slideUp();
  32.    second_li.slideDown(function(){
  33.     first_li.remove().appendTo(obj);
  34.    
  35.    });
  36.   } else if(options.effect == 'fade'){
  37.    first_li.fadeOut(function(){
  38.     obj.css('height',second_li.height());
  39.     second_li.fadeIn();
  40.     first_li.remove().appendTo(obj);
  41.    });
  42.   }
  43.  
  44.   count--;
  45.  
  46.   if(count == 0 && options.run_once){
  47.    clearInterval(interval);
  48.   }
  49.  
  50.       }, options.speed)
  51.     });
  52.   };
  53. })(jQuery);
  54.  </script>
  55. <script type='text/javascript'>
  56.  $(document).ready(function(){
  57.   $('#fade').list_ticker({
  58.    speed:5000,
  59.    effect:'fade'
  60.   });
  61. })
  62.  </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement