麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > JavaScript > 正文

jQuery不間斷滾動效果(模擬百度新聞支持文字/圖片/垂直滾動)

2019-11-20 23:00:26
字體:
供稿:網(wǎng)友
一、jQuery.roll 插件使用說明
jQuery.roll 是模擬百度新聞不間斷滾動效果,并支持文字、圖片水平垂直滾動,該函數(shù)使用方法為:
復(fù)制代碼 代碼如下:

/*
* @module jQuery roll
* @param: contentCls 內(nèi)容容器className
* @param: contentParentId 內(nèi)容容器父元素節(jié)點ID
* @param: configs 配置參數(shù)
*
* @config: effect 滾動效果
* @config: duration 滾動1個像素的運行時間(毫秒數(shù))
* @config: delay 開始滾動的延遲時間(毫秒數(shù))
*
*/
jQuery.roll(contentCls, contentParentId, configs);

二、函數(shù)源碼
復(fù)制代碼 代碼如下:

jQuery.extend({
roll: function(contentCls, contentParentId, configs){
var setTimeID, totalWidth = 0, totalHeight = 0,
firstContent, secondContent, contents;
(function(){
var singleContent, cloneContent, nodeList;
singleContent = $(contentCls, contentParentId);
nodeList = singleContent.children();
if (configs.effect === 'scrollX') {
$.each(nodeList, function(idx, itm) {
totalWidth += $(itm).outerWidth(true);
});
singleContent.css({ 'width': totalWidth + 'px' });
}
else if (configs.effect === 'scrollY') {
$.each(nodeList, function(idx, itm) {
totalHeight += $(itm).outerHeight(true);
});
singleContent.css({ 'height': totalHeight + 'px' });
}
cloneContent = singleContent.clone();
cloneContent.appendTo(contentParentId);
contents = $(contentCls, contentParentId);
firstContent = contents[0];
secondContent = contents[1];
if (configs.effect === 'scrollX') {
$(firstContent).css({ 'left': 0 });
$(secondContent).css({ 'left': totalWidth + 'px' });
}
else if (configs.effect === 'scrollY') {
$(firstContent).css({ 'top': 0 });
$(secondContent).css({ 'top': totalHeight + 'px' });
}
})()
function cssAnimate(){
if (configs.effect === 'scrollX') {
$(firstContent).css({ left: parseInt(firstContent.style.left, 10) - 1 + 'px' });
$(secondContent).css({ left: parseInt(secondContent.style.left, 10) - 1 + 'px' });
$.each(contents, function(idx, itm) {
if (parseInt(itm.style.left,10) === -totalWidth) {
$(itm).css({ left: totalWidth + 'px' });
}
});
}
else if (configs.effect === 'scrollY') {
$(firstContent).css({ top: parseInt(firstContent.style.top, 10) - 1 + 'px' });
$(secondContent).css({ top: parseInt(secondContent.style.top, 10) - 1 + 'px' });
$.each(contents, function(idx, itm) {
if (parseInt(itm.style.top,10) === -totalHeight) {
$(itm).css({ top: totalHeight + 'px' });
}
});
}
setTimeId = setTimeout(cssAnimate, configs.duration);
}
function rollRun(){
setTimeId = setTimeout(cssAnimate, configs.delay);
return jQuery;
}
function rollStop(){
clearTimeout(setTimeId);
return jQuery;
}
return $.extend({
rollRun: rollRun,
rollStop: rollStop
});
}
});

三、完整demo源碼
例3.1
復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="description" content="jQuery實現(xiàn)無間隙滾動效果">
<title>jQuery demo</title>
<style>
body { font: 12px/1.5 tahoma,"microsoft yahei","微軟雅黑E/8F6F/96C5/9ED1"; }
body, div, ul, li, h1 { margin: 0; padding: 0; }
.news { margin: 100px 0 0 100px; }
.news ul { list-style: none; }
.news-box { width: 600px; margin-left: 20px; height: 24px; background-color: #fcfcfd; overflow: hidden; position: relative; _zoom: 1; }
.news h1 { margin-bottom: 15px; padding-left: 20px; color: #370188; }
.news-list { position: absolute; }
.news-list { float: left; }
.news-list li { float: left; _display: inline; margin-right: 15px; height: 24px; line-height: 24px; overflow: hidden; word-wrap: normal; }
.news-list li a { text-decoration: none; color: #000; }
.news-list li a:hover {
-webkit-transition: color .2s linear,background-color .3s linear;
-moz-transition: color .2s linear,background-color .3s linear;
-ms-transition: color .2s linear,background-color .3s linear;
-o-transition: color .2s linear,background-color .3s linear;
transition: color .2s linear,background-color .3s linear;
color: #FF4400;
text-decoration: underline;
}
.news-list li a:visited { color: #290065; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="J_news" class="news">
<h1>文字列表滾動</h1>
<div id="J_Roll_Container" class="news-box">
<ul class="J_Roll_Content news-list">
<li><a target="_blank">日方否認將對中國巡航釣魚島飛機</a></li>
<li><a target="_blank">日本防衛(wèi)省否認將對中國飛機警告射擊(圖)</a></li>
<li><a target="_blank">日否認警告射擊中海監(jiān)飛機 恐中日因奪島開戰(zhàn)</a></li>
</ul>
</div>
</div>
<script>
// 這里引用jQuery.roll代碼
</script>
<script>
$(function(){
var roll_jQuery, contents;
roll_jQuery = $.roll('.J_Roll_Content', '#J_Roll_Container', { effect: 'scrollX', duration: 40, delay: 500 }).rollRun();
contents = $('.J_Roll_Content');
contents.bind('mouseenter', function(){
roll_jQuery.rollStop();
});
contents.bind('mouseleave', function(){
roll_jQuery.rollRun();
});
});
</script>
</body>
</html>

例3.2
復(fù)制代碼 代碼如下:

View Code
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="description" content="jQuery實現(xiàn)無間隙滾動效果">
<title>jQuery demo</title>
<style>
body { font: 12px/1.5 tahoma, "microsoft yahei", "微軟雅黑E/8F6F/96C5/9ED1"; }
body, div, ul, li, h1 { margin: 0; padding: 0; }
.news { margin: 100px 0 0 100px; }
.news ul { list-style: none; }
.news-box { padding: 20px; width: 310px; height: 192px; background-color: #fcfcfd; overflow: hidden; position: relative; }
.news h1 { margin-bottom: 15px; padding-left: 20px; color: #370188; }
.news-list { position: absolute; }
.news-list li { width: 100%; height: 24px; line-height: 24px; overflow: hidden; word-wrap: normal; }
.news-list li a { text-decoration: none; color: #000; }
.news-list li a:hover {
-webkit-transition: color .2s linear, background-color .3s linear;
-moz-transition: color .2s linear, background-color .3s linear;
-ms-transition: color .2s linear, background-color .3s linear;
-o-transition: color .2s linear, background-color .3s linear;
transition: color .2s linear, background-color .3s linear;
color: #FF4400;
text-decoration: underline;
}
.news-list li a:visited { color: #290065; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="J_news" class="news">
<h1>文字列表滾動</h1>
<div id="J_Roll_Container" class="news-box">
<ul class="J_Roll_Content news-list">
<li><a target="_blank">在澳中國留學(xué)生涉嫌接送非法色情業(yè)者賺外快被罰</a></li>
<li><a target="_blank">印度北部等今冬遭遇極寒天氣 已致數(shù)百人被凍死</a></li>
<li><a target="_blank">意大利警方禁止掛中國紅燈籠 被指危險引燃物</a></li>
<li><a target="_blank">日方否認將對中國巡航釣魚島飛機</a></li>
<li><a target="_blank">日本防衛(wèi)省否認將對中國飛機警告射擊(圖)</a></li>
<li><a target="_blank">日否認警告射擊中海監(jiān)飛機 恐中日因奪島開戰(zhàn)</a></li>
<li><a target="_blank">傳解放軍舉行長白山軍演</a></li>
<li><a target="_blank">中國高新6號反潛機問世 反潛艇性能優(yōu)于美軍P-3C</a></li>
<li><a target="_blank">張建剛:2030年中國將圓海洋強國夢</a></li>
<li><a target="_blank">運-20現(xiàn)身試飛中心 可取代伊爾-76任何功能</a></li>
<li><a target="_blank">東海艦隊引入大批無人機 飽和攻擊讓日難以招架</a></li>
</ul>
</div>
</div>
<script>
jQuery.extend({
roll: function(contentCls, contentParentId, configs){
var setTimeID, totalWidth = 0, totalHeight = 0,
firstContent, secondContent, contents;
(function(){
var singleContent, cloneContent, nodeList;
singleContent = $(contentCls, contentParentId);
nodeList = singleContent.children();
if (configs.effect === 'scrollX') {
$.each(nodeList, function(idx, itm) {
totalWidth += $(itm).outerWidth(true);
});
singleContent.css({ 'width': totalWidth + 'px' });
}
else if (configs.effect === 'scrollY') {
$.each(nodeList, function(idx, itm) {
totalHeight += $(itm).outerHeight(true);
});
singleContent.css({ 'height': totalHeight + 'px' });
}
cloneContent = singleContent.clone();
cloneContent.appendTo(contentParentId);
contents = $(contentCls, contentParentId);
firstContent = contents[0];
secondContent = contents[1];
if (configs.effect === 'scrollX') {
$(firstContent).css({ 'left': 0 });
$(secondContent).css({ 'left': totalWidth + 'px' });
}
else if (configs.effect === 'scrollY') {
$(firstContent).css({ 'top': 0 });
$(secondContent).css({ 'top': totalHeight + 'px' });
}
})()
function cssAnimate(){
if (configs.effect === 'scrollX') {
$(firstContent).css({ left: parseInt(firstContent.style.left, 10) - 1 + 'px' });
$(secondContent).css({ left: parseInt(secondContent.style.left, 10) - 1 + 'px' });
$.each(contents, function(idx, itm) {
if (parseInt(itm.style.left,10) === -totalWidth) {
$(itm).css({ left: totalWidth + 'px' });
}
});
}
else if (configs.effect === 'scrollY') {
$(firstContent).css({ top: parseInt(firstContent.style.top, 10) - 1 + 'px' });
$(secondContent).css({ top: parseInt(secondContent.style.top, 10) - 1 + 'px' });
$.each(contents, function(idx, itm) {
if (parseInt(itm.style.top,10) === -totalHeight) {
$(itm).css({ top: totalHeight + 'px' });
}
});
}
setTimeId = setTimeout(cssAnimate, configs.duration);
}
function rollRun(){
setTimeId = setTimeout(cssAnimate, configs.delay);
return jQuery;
}
function rollStop(){
clearTimeout(setTimeId);
return jQuery;
}
return $.extend({
rollRun: rollRun,
rollStop: rollStop
});
}
});
</script>
<script>
$(function(){
var roll_jQuery, contents;
roll_jQuery = $.roll('.J_Roll_Content', '#J_Roll_Container', { effect: 'scrollY', duration: 40, delay: 500 }).rollRun();
contents = $('.J_Roll_Content');
contents.bind('mouseenter', function(){
roll_jQuery.rollStop();
});
contents.bind('mouseleave', function(){
roll_jQuery.rollRun();
});
});
</script>
</body>
</html>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 男女无套免费视频 | 欧美日韩免费一区 | 久久99精品久久久久久久久久久久 | 2021免费日韩视频网 | 国产亚洲综合一区二区 | 国产91丝袜在线播放0 | 亚洲成人激情av | 精品国产一区二区三区免费 | 精品国产成人 | 久久亚洲第一 | 欧美a黄 | 免费黄色欧美视频 | 一边吃奶一边插下面 | 92看片淫黄大片一级 | 欧美人与禽性xxxxx杂性 | 羞羞视频免费网站日本动漫 | 99精美视频 | 国产精品视频yy9299一区 | 久久久久女人精品毛片九一 | 欧美日韩国产成人在线观看 | 狠狠干91| 久草在线免费资源站 | 日本a在线观看 | 精品国产一区二区三区四区阿崩 | 亚洲天堂在线电影 | www.9191.com| 日韩av片网站 | 中文字幕电影免费播放 | 黄色免费大片 | 成人黄色小视频网站 | 久久久免费观看完整版 | 国产无遮挡一级毛片 | 成人免费一区二区 | 97久久精品一区二区三区观看 | 99爱在线免费观看 | 成人免费观看av | 999久久国产| 激情大乳女做爰办公室韩国 | av电影免费在线看 | av在线看网站 | 免费国产一区 |