A client asked for a rotator of customer logo's for their bootstrap3 website. The logo are not a consistent size and the rotator should rotate automatically in an infinite loop.
Here is the CodePen
The animation is not smooth. Particularly on FireFox. Is there a more efficient way to handle the animation?
HTML
<div id="clients_carousel" class="col-md-12 hidden-xs hidden-sm"> <ul id="scroller" class="clearfix"> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/01/keesler.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/07/wcd.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/07/viva.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/07/magma.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/07/safe.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/02/2ndimage.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/02/balboa1.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/02/smile.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/02/nfib.png" alt=""></li> <li><img class="img-responsive" src="http://www.cloudaccess.com/wp-content/uploads/2015/02/dental1-e1424199396391.png" alt=""></li> </ul> </div> CSS
#clients_carousel { position: relative; margin: 0px auto; padding: 0px; width: 100%; height: 40px; overflow: hidden; } #clients_carousel ul { position: absolute; list-style-type: none; top: 0px; left: 0px; height: 40px; margin: 0px; padding: 0px; width: 9999px; } #clients_carousel ul li { float: left; position: relative; margin: 0px; height: 40px; padding: 0px 15px; } #clients_carousel ul li img { height: 40px !important; width: auto !important; } JS
setInterval(function() { if (!$('#clients_carousel ul').is(':animated')) { var fWidth = parseInt($('#clients_carousel ul li:first').outerWidth(true), 10); var lIndent = parseInt($('#clients_carousel ul').css("left"), 10); if (fWidth < Math.abs(lIndent)) { $('#clients_carousel ul li:last').after($('#clients_carousel ul li:first')); var newIndent = lIndent + fWidth; $('#clients_carousel ul').css('left', newIndent + 'px'); lIndent = newIndent; } $('#clients_carousel ul').animate({ left: lIndent - 5 }, 40, "linear"); } }, 41);