/* * vertical news ticker * tadas juozapaitis ( kasp3rito [eta] gmail (dot) com ) * http://www.jugbit.com/jquery-vticker-vertical-news-ticker/ */ (function($){ $.fn.vticker = function(options) { var defaults = { speed: 700, pause: 4000, showitems: 3, animation: '', mousepause: true, ispaused: false, direction: 'up', height: 0 }; var options = $.extend(defaults, options); moveup = function(obj2, height, options){ if(options.ispaused) return; var obj = obj2.children('.list'); var clone = obj.children('.item:first').clone(true); if(options.height > 0) { height = obj.children('.item:first').height(); } obj.animate({top: '-=' + height + 'px'}, options.speed, function() { $(this).children('.item:first').remove(); $(this).css('top', '0px'); }); if(options.animation == 'fade') { obj.children('.item:first').fadeout(options.speed); if(options.height == 0) { obj.children('.item:eq(' + options.showitems + ')').hide().fadein(options.speed).show(); } } clone.appendto(obj); }; movedown = function(obj2, height, options){ if(options.ispaused) return; var obj = obj2.children('.list'); var clone = obj.children('.item:last').clone(true); if(options.height > 0) { height = obj.children('.item:first').height(); } obj.css('top', '-' + height + 'px') .prepend(clone); obj.animate({top: 0}, options.speed, function() { $(this).children('.item:last').remove(); }); if(options.animation == 'fade') { if(options.height == 0) { obj.children('.item:eq(' + options.showitems + ')').fadeout(options.speed); } obj.children('.item:first').hide().fadein(options.speed).show(); } }; return this.each(function() { var obj = $(this); var maxheight = 0; obj.css({overflow: 'hidden', position: 'relative'}) .children('.list').css({position: 'absolute', margin: 0, padding: 0}) // .children('.item').css({margin: 0, padding: 0}); if(options.height == 0) { obj.children('.list').children('.item').each(function(){ if($(this).height() > maxheight) { maxheight = $(this).height(); } }); obj.children('.list').children('.item').each(function(){ $(this).height(maxheight); }); obj.height(maxheight * options.showitems); } else { obj.height(options.height); } var interval = setinterval(function(){ if(options.direction == 'up') { moveup(obj, maxheight, options); } else { movedown(obj, maxheight, options); } }, options.pause); if(options.mousepause) { obj.bind("mouseenter",function(){ options.ispaused = true; }).bind("mouseleave",function(){ options.ispaused = false; }); } }); }; })(jquery);