jquery實現自動滾屏效果,適用用公告新聞等滾屏

來源:互聯網
上載者:User

標籤:style   blog   http   ar   io   color   sp   for   java   

從網路上找到的例子,自己做了下擴充,原樣本是向上滾動,擴充了一個向下滾動的方法:

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>滾屏實驗</title><style type="text/css">ul,li{margin:0;padding:0}#scrollDiv{width:300px;height:100px;min-height:25px;line-height:25px;border:#ccc 1px solid;overflow:hidden}#scrollDiv li{height:25px;padding-left:10px;}</style>    <script src="js/jquery-1.4.1.js"></script><script type="text/javascript">    (function ($) {        $.fn.extend({            Scroll: function (opt, callback) {                //參數初始化                if (!opt) var opt = {};                var _this = this.eq(0).find("ul:first");                var lineH = _this.find("li:first").height(), //擷取行高                        line = opt.line ? parseInt(opt.line, 10) : parseInt(this.height() / lineH, 10), //每次滾動的行數,預設為一屏,即父容器高度                        speed = opt.speed ? parseInt(opt.speed, 10) : 500, //捲動速度,數值越大,速度越慢(毫秒)                        timer = opt.timer ? parseInt(opt.timer, 10) : 2000; //滾動的時間間隔(毫秒)                if (line == 0) line = 1;                var upHeight = 0 - line * lineH;                var downHeight=line * lineH - 0;                //滾動函數                scrollUp = function () {                    _this.animate(                        { marginTop: upHeight },                        speed,                        function () {                            for (i = 1; i <= line; i++) {                                _this.find("li:first").appendTo(_this);                            }                            _this.css({ marginTop: 0 });                        }                    );                },                //向下滾動函數                scrollDown = function () {                    _this.animate(                        { marginTop: downHeight },//動畫展示css樣式                        speed,                        function () {                            _this.find("li:last").prependTo(_this);                            _this.css({ marginTop: 0 });                        }                        )                }                var timerID                //滑鼠事件綁定                _this.hover(function () {                    clearInterval(timerID);                }, function () {                    timerID = setInterval("scrollDown()", timer);//這裡調用向下或者向上滾動函數                }).mouseout();            }        })    })(jQuery);    $(document).ready(function () {        $("#scrollDiv").Scroll({ line: 1, speed: 500, timer: 2000 });    });</script></head><body><p>多行滾動示範:</p><div id="scrollDiv">  <ul>    <li>這是公告標題的第1行</li>    <li>這是公告標題的第2行</li>    <li>這是公告標題的第3行</li>    <li>這是公告標題的第4行</li>    <li>這是公告標題的第5行</li>    <li>這是公告標題的第6行</li>    <li>這是公告標題的第7行</li>    <li>這是公告標題的第8行</li>  </ul></div></body></html>

 

jquery實現自動滾屏效果,適用用公告新聞等滾屏

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.