效果圖如下:
jQuery News Ticker 是一款相當便利的 jQuery 插件,能讓你迅速做出如圖般的新聞行情跑馬燈效果。
它可以透過清單、HTML,甚至 RSS(僅限載入本站 RSS feed)來產生新聞內容,並支援上一則、下一則與暫停播放等操作。這個插件提供了一系列自訂選項,例如:
整體程式碼開發簡單而高效。
首先引入 jQuery News Ticker 的樣式與腳本(別忘了先載入 jQuery 本體):
<link href="css/ticker-style.css" rel="stylesheet" type="text/css" /> <script src="jquery.ticker.js" type="text/javascript"></script>
接著撰寫 HTML 結構:
<div id="ticker-wrapper" class="no-js"> <ul id="js-news" class="js-hidden"> <li class="news-item"><a href="#">This is the 1st latest news item.</a></li> <li class="news-item"><a href="#">This is the 2nd latest news item.</a></li> <li class="news-item"><a href="#">This is the 3rd latest news item.</a></li> <li class="news-item"><a href="#">This is the 4th latest news item.</a></li> </ul> </div>
最後以 JavaScript 啟用它:
<script type="text/javascript">
$(function () {
$('#js-news').ticker();
});
</script>
官方網站:https://www.gbin1.com/technology/jquerynews/20111105jquerypluginnewsticker/demo.html