News Ticker Issue
News Ticker Issue
by ashu_mdu
HTML
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<div id="ticker">
<ul class="news-list">
<li><p>My Paragraph<br/> with break.</p></li>
<li>"You've gotta dance like there's nobody watching, <br/> with break. Love like you'll never be hurt, <br/> with break. Sing like there's nobody listening, And live like it's heaven on earth<br/> with break." - <strong><i>William W. Purkey</i></strong>"There are only two ways to <br/> with break. live your life. One is as though nothing <br/> with break. is a miracle. The other is as <br/> with break.though everything is a miracle." - <strong><i>Albert <br/> with break.Einstein</i></strong></li>
<li><ul><li>My Paragraph</li></ul></li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=69157">Link to Google</a></li>
<li>"You've gotta dance like there's nobody watching, <br/> with break. Love like you'll never be hurt, <br/> with break. Sing like there's nobody listening, And live like it's heaven on earth<br/> with break." - <strong><i>William W. Purkey</i></strong>"There are only two ways to <br/> with break. live your life. One is as though nothing <br/> with break. is a miracle. The other is as <br/> with break.though everything is a miracle." - <strong><i>Albert <br/> with break.Einstein</i></strong></li>
<li>"Be the change that you wish to see in the world." - <strong><i>Mahatma Gandhi</i></strong></li>
<li>"There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle." - <strong><i>Albert Einstein</i></strong></li>
</ul>
</div>
CSS
#ticker{line-height: 1.8em;max-width:600px;color:#000;min-height:40px; height:auto;}
.news-list{padding:0;margin:0;list-style-type:none;}
ul.news-list > li{position:absolute;white-space: nowrap;display:none;}
JavaScript
var ticker=$("#ticker");var t;var li_count=1;var li_length=$("ul.news-list li").length;var li=$("li").first();var runTicker=function(trans_width){$(li).css({"left":+trans_width+"px"});t=setInterval(function(){if(parseInt($(li).css("left"))>-$(li).width()){$(li).css({"left":parseInt($(li).css("left"))-1+"px","display":"block"})}else{clearInterval(t);trans_width=ticker.width();li=$(li).next();if(li_count==li_length){li_count=1;li=$("li").first();runTicker(trans_width)}else if(li_count<li_length){li_count++;setTimeout(function(){runTicker(trans_width)},500)}}},20)};$(ticker).hover(function(){clearInterval(t)},function(){runTicker(parseInt($(li).css("left")))});runTicker(ticker.width());