基于jQuery的公告無限循環(huán)滾動(dòng)實(shí)現(xiàn)代碼
更新時(shí)間:2012年05月11日 16:52:38 作者:
今天看到一個(gè)網(wǎng)站的公告欄一個(gè)小效果,如果有2條公告或以上就有個(gè)滾動(dòng)效果,特整理下分享給大家
在線演示:http://demo.jb51.net/js/2012/callboard/
jQuery代碼
//第二版:Newton改造
(function (win){
var callboarTimer;
var callboard = $('#callboard');
var callboardUl = callboard.find('ul');
var callboardLi = callboard.find('li');
var liLen = callboard.find('li').length;
var initHeight = callboardLi.first().outerHeight(true);
win.autoAnimation = function (){
if (liLen <= 1) return;
var self = arguments.callee;
var callboardLiFirst = callboard.find('li').first();
callboardLiFirst.animate({
marginTop:-initHeight
}, 500, function (){
clearTimeout(callboarTimer);
callboardLiFirst.appendTo(callboardUl).css({marginTop:0});
callboarTimer = setTimeout(self, 5000);
});
}
callboard.mouseenter(
function (){
clearTimeout(callboarTimer);
}).mouseleave(function (){
callboarTimer = setTimeout(win.autoAnimation, 5000);
});
}(window));
setTimeout(window.autoAnimation, 5000);
HTML代碼:
<div id="callboard">
<ul>
<li>
<a >公告:前端組主題正在整理中..有需要用的朋友請留個(gè)言,以方便及時(shí)通知!</a>
</li>
<li>
<span style="color:red;">公告:前端組上線一個(gè)月零八天,PR升為3,BD權(quán)重1</span>
</li>
</ul>
CSS代碼:(可根據(jù)需求另設(shè))
#callboard { height:24px; line-height:24px; overflow:hidden;}
#callboard ul { padding:0;}
#callboard li { padding:0;}
完整演示代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>滾動(dòng)公告欄</title>
<style type="text/css">
header, nav, aside, menu, figure, article, footer { display:block; }
body, div, form, textarea, label, input, ul, ol, li, dl, dt, dd, p, span, a, img, h1, h2, h3, h4, h5, h6, tbody, tfoot, tr, th, td, pre, code, form, fieldset, legend, font { margin:0; padding:0; }
table { border-collapse:collapse; border-spacing:0; }
caption, th { text-align:left; }
sup { vertical-align:text-top; }
sub { vertical-align:text-bottom; }
li { list-style:none; }
fieldset, img { border:none; }
input, textarea, select { font-family:inherit; font-size:inherit; font-weight:inherit; *font-size:100%;
color:inherit; _color:#333; *color:#333;
outline:none; }
/*BASE CLASS*/
.cfix { *display:inline-block;*zoom:1}
.cfix:after { content:"."; display:block; height:0; clear:both; visibility:hidden; }
/*公告欄滾動(dòng)CSS*/
#callboard { width:600px; margin:100px auto 0; height:24px; line-height:24px; overflow:hidden; font-size:12px; background-color:#f5f5f5;}
#callboard ul { padding:0; }
#callboard li { padding:0; }
</style>
<script type="text/javascript" src="http://demo.jb51.net/jslib/jquery/jquery-1.7.2.min.js"></script>
</head>
<body>
<div id="callboard">
<ul>
<li>
<span style="color:red;">公告[2]:前端組上線一個(gè)月零八天,PR升為3,BD權(quán)重1</span>
</li>
<li>
<span style="color:red;">公告[3]:撤下了BloggerAds,原因?yàn)槭杖胩?,打開速度慢!</span>
</li>
<li style="margin-top: 0px;">
<a href="http://chabaoo.cn">公告[1]:前端組主題正在整理中..有需要用的朋友請留個(gè)言,以方便及時(shí)通知!</a>
</li>
</ul>
</div>
<!--公告板滾動(dòng)-->
<script type="text/javascript">
(function (win){
var callboarTimer;
var callboard = $('#callboard');
var callboardUl = callboard.find('ul');
var callboardLi = callboard.find('li');
var liLen = callboard.find('li').length;
var initHeight = callboardLi.first().outerHeight(true);
win.autoAnimation = function (){
if (liLen <= 1) return;
var self = arguments.callee;
var callboardLiFirst = callboard.find('li').first();
callboardLiFirst.animate({
marginTop:-initHeight
}, 500, function (){
clearTimeout(callboarTimer);
callboardLiFirst.appendTo(callboardUl).css({marginTop:0});
callboarTimer = setTimeout(self, 5000);
});
}
callboard.mouseenter(
function (){
clearTimeout(callboarTimer);
}).mouseleave(function (){
callboarTimer = setTimeout(win.autoAnimation, 5000);
});
}(window));
setTimeout(window.autoAnimation, 5000);
</script>
</body>
</html>
jQuery代碼
復(fù)制代碼 代碼如下:
//第二版:Newton改造
(function (win){
var callboarTimer;
var callboard = $('#callboard');
var callboardUl = callboard.find('ul');
var callboardLi = callboard.find('li');
var liLen = callboard.find('li').length;
var initHeight = callboardLi.first().outerHeight(true);
win.autoAnimation = function (){
if (liLen <= 1) return;
var self = arguments.callee;
var callboardLiFirst = callboard.find('li').first();
callboardLiFirst.animate({
marginTop:-initHeight
}, 500, function (){
clearTimeout(callboarTimer);
callboardLiFirst.appendTo(callboardUl).css({marginTop:0});
callboarTimer = setTimeout(self, 5000);
});
}
callboard.mouseenter(
function (){
clearTimeout(callboarTimer);
}).mouseleave(function (){
callboarTimer = setTimeout(win.autoAnimation, 5000);
});
}(window));
setTimeout(window.autoAnimation, 5000);
HTML代碼:
復(fù)制代碼 代碼如下:
<div id="callboard">
<ul>
<li>
<a >公告:前端組主題正在整理中..有需要用的朋友請留個(gè)言,以方便及時(shí)通知!</a>
</li>
<li>
<span style="color:red;">公告:前端組上線一個(gè)月零八天,PR升為3,BD權(quán)重1</span>
</li>
</ul>
CSS代碼:(可根據(jù)需求另設(shè))
復(fù)制代碼 代碼如下:
#callboard { height:24px; line-height:24px; overflow:hidden;}
#callboard ul { padding:0;}
#callboard li { padding:0;}
完整演示代碼:
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>滾動(dòng)公告欄</title>
<style type="text/css">
header, nav, aside, menu, figure, article, footer { display:block; }
body, div, form, textarea, label, input, ul, ol, li, dl, dt, dd, p, span, a, img, h1, h2, h3, h4, h5, h6, tbody, tfoot, tr, th, td, pre, code, form, fieldset, legend, font { margin:0; padding:0; }
table { border-collapse:collapse; border-spacing:0; }
caption, th { text-align:left; }
sup { vertical-align:text-top; }
sub { vertical-align:text-bottom; }
li { list-style:none; }
fieldset, img { border:none; }
input, textarea, select { font-family:inherit; font-size:inherit; font-weight:inherit; *font-size:100%;
color:inherit; _color:#333; *color:#333;
outline:none; }
/*BASE CLASS*/
.cfix { *display:inline-block;*zoom:1}
.cfix:after { content:"."; display:block; height:0; clear:both; visibility:hidden; }
/*公告欄滾動(dòng)CSS*/
#callboard { width:600px; margin:100px auto 0; height:24px; line-height:24px; overflow:hidden; font-size:12px; background-color:#f5f5f5;}
#callboard ul { padding:0; }
#callboard li { padding:0; }
</style>
<script type="text/javascript" src="http://demo.jb51.net/jslib/jquery/jquery-1.7.2.min.js"></script>
</head>
<body>
<div id="callboard">
<ul>
<li>
<span style="color:red;">公告[2]:前端組上線一個(gè)月零八天,PR升為3,BD權(quán)重1</span>
</li>
<li>
<span style="color:red;">公告[3]:撤下了BloggerAds,原因?yàn)槭杖胩?,打開速度慢!</span>
</li>
<li style="margin-top: 0px;">
<a href="http://chabaoo.cn">公告[1]:前端組主題正在整理中..有需要用的朋友請留個(gè)言,以方便及時(shí)通知!</a>
</li>
</ul>
</div>
<!--公告板滾動(dòng)-->
<script type="text/javascript">
(function (win){
var callboarTimer;
var callboard = $('#callboard');
var callboardUl = callboard.find('ul');
var callboardLi = callboard.find('li');
var liLen = callboard.find('li').length;
var initHeight = callboardLi.first().outerHeight(true);
win.autoAnimation = function (){
if (liLen <= 1) return;
var self = arguments.callee;
var callboardLiFirst = callboard.find('li').first();
callboardLiFirst.animate({
marginTop:-initHeight
}, 500, function (){
clearTimeout(callboarTimer);
callboardLiFirst.appendTo(callboardUl).css({marginTop:0});
callboarTimer = setTimeout(self, 5000);
});
}
callboard.mouseenter(
function (){
clearTimeout(callboarTimer);
}).mouseleave(function (){
callboarTimer = setTimeout(win.autoAnimation, 5000);
});
}(window));
setTimeout(window.autoAnimation, 5000);
</script>
</body>
</html>
您可能感興趣的文章:
- 利用10行js代碼實(shí)現(xiàn)上下滾動(dòng)公告效果
- js向上無縫滾動(dòng),網(wǎng)站公告效果 具體代碼
- 原生js實(shí)現(xiàn)公告滾動(dòng)效果
- jQuery實(shí)現(xiàn)公告文字左右滾動(dòng)的實(shí)例代碼
- Jquery公告滾動(dòng)+AJAX后臺(tái)得到數(shù)據(jù)
- jquery垂直公告滾動(dòng)實(shí)現(xiàn)代碼
- jQuery實(shí)現(xiàn)上下滾動(dòng)公告欄詳細(xì)代碼
- jQuery實(shí)現(xiàn)單行文字間歇向上滾動(dòng)源代碼
- jquery插件之文字間歇自動(dòng)向上滾動(dòng)效果代碼
- jQuery實(shí)現(xiàn)的文字逐行向上間歇滾動(dòng)效果示例
- JavaScript實(shí)現(xiàn)的滾動(dòng)公告特效【基于jQuery】
相關(guān)文章
jquery操作checked屬性以及disabled屬性的多種方法
這篇文章主要介紹了jquery控制checked屬性以及disabled屬性的多種方法,下面只提到checked,其實(shí)disabled在jquery里的用法和checked是一模一樣的,需要的朋友可以參考下2014-06-06實(shí)例代碼講解jquery easyui動(dòng)態(tài)tab頁
這篇文章主要介紹了實(shí)例代碼講解jquery easyui動(dòng)態(tài)tab頁的相關(guān)資料,需要的朋友可以參考下2015-11-11jquery實(shí)現(xiàn)圖片滾動(dòng)效果的簡單實(shí)例
這篇文章主要介紹了jquery實(shí)現(xiàn)圖片滾動(dòng)效果的簡單實(shí)例,有需要的朋友可以參考一下2013-11-11jQuery:節(jié)點(diǎn)(插入,復(fù)制,替換,刪除)操作
jQuery:節(jié)點(diǎn)(插入,復(fù)制,替換,刪除)操作,需要的朋友可以參考一下2013-03-03