1/* 2 * 3 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk) 4 * Licensed under the MIT License: 5 * http://www.opensource.org/licenses/mit-license.php 6 * 7 * Version 2.0 8 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/ 9 * 10 * $LastChangedDate$ 11 * $Rev$ 12 * 13 */ 14 15(function($) { 16/* 17 * A basic news ticker. 18 * 19 * @name newsticker (or newsTicker) 20 * @param delay Delay (in milliseconds) between iterations. Default 4 seconds (4000ms) 21 * @author Sam Collett (http://www.texotela.co.uk) 22 * @example $("#news").newsticker(); // or $("#news").newsTicker(5000); 23 * 24 */ 25$.fn.newsTicker = $.fn.newsticker = function(delay) 26{ 27 delay = delay || 4000; 28 initTicker = function(el) 29 { 30 stopTicker(el); 31 el.items = $("li", el); 32 // hide all items (except first one) 33 el.items.not(":eq(0)").hide().end(); 34 // current item 35 el.currentitem = 0; 36 startTicker(el); 37 }; 38 startTicker = function(el) 39 { 40 el.tickfn = setInterval(function() { doTick(el) }, delay) 41 }; 42 stopTicker = function(el) 43 { 44 clearInterval(el.tickfn); 45 }; 46 pauseTicker = function(el) 47 { 48 el.pause = true; 49 }; 50 resumeTicker = function(el) 51 { 52 el.pause = false; 53 }; 54 doTick = function(el) 55 { 56 // don't run if paused 57 if(el.pause) return; 58 // pause until animation has finished 59 el.pause = true; 60 // hide current item 61 $(el.items[el.currentitem]).fadeOut("slow", 62 function() 63 { 64 $(this).hide(); 65 // move to next item and show 66 el.currentitem = ++el.currentitem % (el.items.size()); 67 $(el.items[el.currentitem]).fadeIn("slow", 68 function() 69 { 70 el.pause = false; 71 } 72 ); 73 } 74 ); 75 }; 76 this.each( 77 function() 78 { 79 if(this.nodeName.toLowerCase()!= "ul") return; 80 initTicker(this); 81 } 82 ) 83 .addClass("newsticker") 84 .hover( 85 function() 86 { 87 // pause if hovered over 88 pauseTicker(this); 89 }, 90 function() 91 { 92 // resume when not hovered over 93 resumeTicker(this); 94 } 95 ); 96 return this; 97}; 98 99})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.