Created
September 22, 2011 17:17
-
-
Save chrispecora/1235385 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html xmlns="http://www.w3.org/1999/xhtml"> | |
| <script type="text/javascript"> | |
| $(document).ready(function(){ | |
| $('#ticker').list_ticker({ | |
| speed:2000, | |
| effect:'fade', | |
| run_once:false | |
| }) | |
| }) | |
| </script> | |
| <body> | |
| <ul id="ticker"> | |
| <li>Item 1</li> | |
| <li>Item 2</li> | |
| <li>Item 3</li> | |
| </ul> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($){ | |
| $.fn.list_ticker = function(options){ | |
| var defaults = { | |
| speed:4000, | |
| effect:'slide', | |
| run_once:false | |
| }; | |
| var options = $.extend(defaults, options); | |
| return this.each(function(){ | |
| var obj = $(this); | |
| var list = obj.children(); | |
| var count = list.length - 1; | |
| list.not(':first').hide(); | |
| var interval = setInterval(function(){ | |
| list = obj.children(); | |
| list.not(':first').hide(); | |
| var first_li = list.eq(0) | |
| var second_li = list.eq(Math.floor(Math.random()*list.length)); | |
| if(options.effect == 'slide'){ | |
| first_li.slideUp(); | |
| second_li.slideDown(function(){ | |
| first_li.remove().appendTo(obj); | |
| }); | |
| } else if(options.effect == 'fade'){ | |
| first_li.fadeOut(function(){ | |
| obj.css('height',second_li.height()); | |
| second_li.fadeIn(); | |
| first_li.remove().appendTo(obj); | |
| }); | |
| } | |
| count--; | |
| if(count == 0 && options.run_once){ | |
| clearInterval(interval); | |
| } | |
| }, options.speed) | |
| }); | |
| }; | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment