jquery - Horizontally centering a scrolling list -
jquery - Horizontally centering a scrolling list -
i trying have text cycle through list of phrase, display on same line , centered no matter string length , screen size. have been able text cycle through , display on same line finding thread here on se. issue having trying center text within parenting div. strings going different lengths cannot set width , s need absolutely positioned display on same line.
i have been scratching head on how accomplish , have exhausted google , myself. know how accomplish effect?
jsfiddle on have far: http://jsfiddle.net/eh3sxko8/
html:
<div class="container"> <ul id="cyclelist"> <li>some title</li> <li>another title</li> <li>yet another</li> </ul> </div>
css:
.container{ width:100%; } ul#cyclelist { position:relative; overflow:hidden; height:50px; } ul#cyclelist li { opacity:0; position:absolute; overflow:hidden; }
js:
$(document).ready(function() { var j = 0; var delay = 2000; //millisecond delay between cycles function cyclethru(){ var jmax = $("ul#cyclelist li").length -1; $("ul#cyclelist li:eq(" + j + ")") .animate({"opacity" : "1"} ,400) .animate({"opacity" : "1"}, delay) .animate({"opacity" : "0"}, 400, function(){ (j == jmax) ? j=0 : j++; cyclethru(); }); }; cyclethru(); });
please check this: jsfiddle.
css:
ul#cyclelist { padding-left: 0px; } ul#cyclelist li { width: 100%; text-align: center; }
jquery html css
Comments
Post a Comment