»
EnglishFrenchVietnamese

Print - JavaScript Simple News Ticker with jQuery - JavaScriptBank.com

Full version: jsB@nk » Framework » jQuery » JavaScript Simple News Ticker with jQuery
URL: http://www.javascriptbank.com/javascript-simple-news-ticker-with-jquery.html

JavaScript Simple News Ticker with jQuery © JavaScriptBank.comA simple JavaScript (operated by jQuery) code to create a news ticker that scrolling up continuously. The code is very easy to setup and can be edited to suit the purpose of usage, and with the support of CSS, this news ticker becomes very eye-catching.

Full version: jsB@nk » Framework » jQuery » JavaScript Simple News Ticker with jQuery
URL: http://www.javascriptbank.com/javascript-simple-news-ticker-with-jquery.html



CSS
<style type="text/css">#ticker { width:180px; height:300px; border:1px solid #aaaaaa; overflow:auto; text-align: left; }#ticker dt { font:normal 14px Georgia; padding:0 10px 5px 10px; background-color:#e5e5e5; padding-top:10px; border:1px solid #ffffff; border-bottom:none; border-right:none; position:relative; }#ticker dd { margin-left:0; font:normal 11px Verdana; padding:0 10px 10px 10px; border-bottom:1px solid #aaaaaa; background-color:#e5e5e5; border-left:1px solid #ffffff; position:relative; }#ticker dd.last { border-bottom:1px solid #ffffff; }#ticker div { margin-top:0; }</style>


JavaScript
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>    <script type="text/javascript">  $(function() {  //cache the tickervar ticker = $("#ticker");  //wrap dt:dd pairs in divsticker.children().filter("dt").each(function() {    var dt = $(this),    container = $("<div>");    dt.next().appendTo(container);  dt.prependTo(container);    container.appendTo(ticker);});//hide the scrollbarticker.css("overflow", "hidden");//animator functionfunction animator(currentItem) {      //work out new anim duration  var distance = currentItem.height();duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.025;  //animate the first child of the ticker  currentItem.animate({ marginTop: -distance }, duration, "linear", function() {    //move current item to the bottomcurrentItem.appendTo(currentItem.parent()).css("marginTop", 0);//recurseanimator(currentItem.parent().children(":first"));  }); };//start the tickeranimator(ticker.children(":first"));//set mouseenterticker.mouseenter(function() {    //stop current animation  ticker.children().stop();  });//set mouseleaveticker.mouseleave(function() {                    //resume animation  animator(ticker.children(":first"));  });  });    </script>


HTML
<div id="tickerContainer">      <dl id="ticker">        <dt class="heading">This is a news title!</dt><dd class="text">This is a snippet of the news. It could be the whole news item or it could link to another page containing...</dd>        <dt class="heading">News Heading 2</dt><dd class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</dd>        <dt class="heading">News Heading 3</dt><dd class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</dd>        <dt class="heading">News Heading 4</dt><dd class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</dd>        <dt class="heading">This item is long!</dt><dd class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</dd>      </dl>    </div>