jQuery實(shí)現(xiàn)公告新聞自動(dòng)滾屏效果實(shí)例代碼
來源:易賢網(wǎng) 閱讀:1180 次 日期:2016-07-27 15:26:49
溫馨提示:易賢網(wǎng)小編為您整理了“jQuery實(shí)現(xiàn)公告新聞自動(dòng)滾屏效果實(shí)例代碼”,方便廣大網(wǎng)友查閱!

本文是小編參考網(wǎng)絡(luò)上的一個(gè)小demo,自己做了下擴(kuò)展,原來是向上滾動(dòng)的,擴(kuò)展了一個(gè)向下滾動(dòng)的方法,具體實(shí)例代碼如下所示:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>滾屏實(shí)驗(yàn)</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) {

//參數(shù)初始化

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), //每次滾動(dòng)的行數(shù),默認(rèn)為一屏,即父容器高度

speed = opt.speed ? parseInt(opt.speed, 10) : 500, //卷動(dòng)速度,數(shù)值越大,速度越慢(毫秒)

timer = opt.timer ? parseInt(opt.timer, 10) : 2000; //滾動(dòng)的時(shí)間間隔(毫秒)

if (line == 0) line = 1;

var upHeight = 0 - line * lineH;

var downHeight=line * lineH - 0;

//滾動(dòng)函數(shù)

scrollUp = function () {

_this.animate(

{ marginTop: upHeight },

speed,

function () {

for (i = 1; i <= line; i++) {

_this.find("li:first").appendTo(_this);

}

_this.css({ marginTop: 0 });

}

);

},

//向下滾動(dòng)函數(shù)

scrollDown = function () {

_this.animate(

{ marginTop: downHeight },//動(dòng)畫展示css樣式

speed,

function () {

_this.find("li:last").prependTo(_this);

_this.css({ marginTop: 0 });

}

)

}

var timerID

//鼠標(biāo)事件綁定

_this.hover(function () {

clearInterval(timerID);

}, function () {

timerID = setInterval("scrollDown()", timer);//這里調(diào)用向下或者向上滾動(dòng)函數(shù)

}).mouseout();

}

})

})(jQuery);

$(document).ready(function () {

$("#scrollDiv").Scroll({ line: 1, speed: 500, timer: 2000 });

});

</script>

</head>

<body>

<p>多行滾動(dòng)演示:</p>

<div id="scrollDiv">

<ul>

<li>這是公告標(biāo)題的第1行</li>

<li>這是公告標(biāo)題的第2行</li>

<li>這是公告標(biāo)題的第3行</li>

<li>這是公告標(biāo)題的第4行</li>

<li>這是公告標(biāo)題的第5行</li>

<li>這是公告標(biāo)題的第6行</li>

<li>這是公告標(biāo)題的第7行</li>

<li>這是公告標(biāo)題的第8行</li>

</ul>

</div>

</body>

</html>

以上所述是小編給大家介紹的jQuery實(shí)現(xiàn)公告新聞自動(dòng)滾屏效果實(shí)例代碼,希望對(duì)大家有所幫助

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)