JavaScript Suggestion
-
Hi guys!
First of all thank you for this really great plugin. Works good. But I found some disturbing bugs, such as high cpu usage and big white space between ending and staring.
So I decided to help you to improve this plugin and I merged liScroll 1.0 and webTicker 1.3. Here is the right and working script:jQuery.fn.liScroll = function(settings) { settings = jQuery.extend({ travelocity: 0.05, direction: 1, moving: true }, settings); return this.each(function(){ var $strip = jQuery(this); $strip.addClass("newsticker") var stripWidth = 0; var $mask = $strip.wrap("<div class='mask'></div>"); var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>"); $strip.find("li").each(function(i){ stripWidth += jQuery(this, i).outerWidth(true); }); $strip.width(stripWidth+200);//20 used for ie9 fix function scrollnews(spazio, tempo){ if (settings.direction == 1) $strip.animate({left: '-='+ spazio}, tempo, "linear", function(){ $strip.children().last().after($strip.children().first()); var first = $strip.children().first(); var width = first.outerWidth(true); var defTiming = width/settings.travelocity; //$strip.css("left", left); $strip.css("left", '0'); scrollnews(width, defTiming); }); else $strip.animate({right: '-='+ spazio}, tempo, "linear", function(){ $strip.children().last().after($strip.children().first()); var first = $strip.children().first(); var width = first.outerWidth(true); var defTiming = width/settings.travelocity; //$strip.css("left", left); $strip.css("right", '0'); scrollnews(width, defTiming); }); } var first = $strip.children().first(); var travel = first.outerWidth(true); var timing = travel/settings.travelocity; scrollnews(travel, timing); $strip.hover(function(){ jQuery(this).stop(); }, function(){ var offset = jQuery(this).offset(); var first = $strip.children().first(); var width = first.outerWidth(true); var residualSpace; if (settings.direction == 1) residualSpace = parseInt(jQuery(this).css('left').replace('px',''))+ width; else residualSpace = parseInt(jQuery(this).css('right').replace('px',''))+ width; var residualTime = residualSpace/settings.travelocity; scrollnews(residualSpace, residualTime); }); }); };
Use it with joy! 😉
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘JavaScript Suggestion’ is closed to new replies.