基于jquery可配置循環(huán)左右滾動(dòng)例子
<!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>
<title>可配置橫欄滾動(dòng)Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
* { margin:0; padding:0;}
body { font-size:12px;}
</style>
<script src="jquery-1.4.1.js" type="text/javascript"></script>
<style type="text/css">
#scrollable {
background-color:#efefef;
border:1px solid #ddd;
padding:10px 8px;
width:523px;
height:65px;
margin-top:30px;
}
div.items {
height:66px;
margin-left:8px;
float:left;
width:475px !important;
}
div.items a {
display:block;
float:left;
margin-right:8px;
width:88px;
height:66px;
background:#BBB;
font-size:50px;
color:#ccc;
line-height:66px;
text-decoration:none;
text-align:center;
cursor:pointer;
}
div.items a:hover {
color:#999;
}
div.items a.active {
background-position:-174px 0;
color:#555;
cursor:default;
}
a.prev, a.next {
background:url(left.png) no-repeat 0 0;
display:block;
width:18px;
height:18px;
float:left;
margin:22px 0 0 0;
cursor:pointer;
}
a.next {
background-image:url(right.png)
}
a.prev:hover {
background-position:0 -18px;
}
a.next:hover {
background-position:0 -18px;
}
</style>
<script language="javascript" type="text/javascript">
(function ($) {
$.fn.extend({
Scroll: function (opt, callback) {
if (!opt) var opt = {};
var _btnleft = $(opt.left);
var _btnright = $(opt.right);
var timerID;
var _this = this.eq(0).find("div").eq(1);
var lineW = _this.find("a:first").width(), //獲取列寬
line = opt.line ? parseInt(opt.line, 10) : parseInt(_this.width() / lineW, 10), //每次滾動(dòng)的列數(shù),默認(rèn)為一屏,即父容器列寬
speed = opt.speed ? parseInt(opt.speed, 10) : 500; //滾動(dòng)速度,數(shù)值越大,速度越慢(毫秒)
timer = opt.timer ? parseInt(opt.timer, 10) : 3000; //滾動(dòng)的時(shí)間間隔(毫秒)
if (line == 0) line = 1;
var upWidth = 0 - line * lineW;
//滾動(dòng)函數(shù)
var scrollLeft = function () {
if (!_this.is(":animated")) {
_this.animate({
left: upWidth
}, speed, function () {
for (i = 1; i <= line; i++) {
_this.find("a:first").appendTo(_this);
}
_this.css({ left: 0 });
});
}
}
var scrollRight = function () {
if (!_this.is(":animated")) {
for (i = 1; i <= line; i++) {
_this.find("a:last").show().prependTo(_this);
}
_this.css({ left: upWidth });
_this.animate({
left: 0
}, speed, function () {
});
}
} //Shawphy:自動(dòng)播放
var autoPlay = function () {
if (timer) timerID = window.setInterval(scrollLeft, timer);
};
var autoStop = function () {
if (timer) window.clearInterval(timerID);
}; //鼠標(biāo)事件綁定
_this.hover(autoStop, autoPlay).mouseout();
_btnleft.css("cursor", "pointer").click(scrollLeft).hover(autoStop, autoPlay);
_btnright.css("cursor", "pointer").click(scrollRight).hover(autoStop, autoPlay);
}
})
})(jQuery);
$(document).ready(function () {
$("#scrollable").Scroll({ line: 5, speed: 500, timer: 3000, left: ".prev", right: ".next"});
});
</script>
</head>
<body>
<div style="margin:0 auto;width:500px;">
<div id="scrollable">
<a class="prev" href="#"></a>
<div class="items" style="overflow: hidden; position: relative; visibility: visible; width: 478px;">
<div style="position: absolute; width: 200000em; left: 0px;" class="scrollable_demo">
<a>1</a>
<a>2</a>
<a>3</a>
<a>4</a>
<a>5</a>
<a>6</a>
<a>7</a>
<a>8</a>
<a>9</a>
<a>10</a>
<a>11</a>
<a>12</a>
<a>13</a>
<a>14</a>
<a>15</a>
</div>
<br clear="all"/>
</div>
<a class="next" href="#"></a>
</div>
</div>
</body>
</html>
說(shuō)明:1、需要兩個(gè)圖片
left.png:
right.png:
2、需要引入jquery的包,這個(gè)應(yīng)該不用說(shuō)的......
- jQuery控制li上下循環(huán)滾動(dòng)插件用法實(shí)例(附demo源碼下載)
- 多種JQuery循環(huán)滾動(dòng)文字圖片效果代碼
- jQuery實(shí)現(xiàn)列表自動(dòng)滾動(dòng)循環(huán)滾動(dòng)展示新聞
- jQuery循環(huán)滾動(dòng)新聞列表示例代碼
- jQuery實(shí)現(xiàn)列表自動(dòng)循環(huán)滾動(dòng)鼠標(biāo)懸停時(shí)停止?jié)L動(dòng)
- jquery實(shí)現(xiàn)文字由下到上循環(huán)滾動(dòng)的實(shí)例代碼
- jQuery循環(huán)滾動(dòng)展示代碼 可應(yīng)用到文字和圖片上
- 基于jQuery的公告無(wú)限循環(huán)滾動(dòng)實(shí)現(xiàn)代碼
- JQuery循環(huán)滾動(dòng)圖片代碼
- 基于jquery的內(nèi)容循環(huán)滾動(dòng)小模塊(仿新浪微博未登錄首頁(yè)滾動(dòng)微博顯示)
- 使用jquery實(shí)現(xiàn)的循環(huán)連續(xù)可停頓滾動(dòng)實(shí)例
相關(guān)文章
jquery拖拽效果完整實(shí)例(附demo源碼下載)
這篇文章主要介紹了jquery拖拽效果實(shí)現(xiàn)方法,詳細(xì)介紹了jQuery實(shí)現(xiàn)拖拽功能的具體步驟與相關(guān)技巧,并附代碼了demo源碼供讀者下載參考,需要的朋友可以參考下2016-01-01jQuery之網(wǎng)頁(yè)換膚實(shí)現(xiàn)代碼
用jQuery做網(wǎng)頁(yè)換膚確實(shí)是很一個(gè)很巧妙,很好的選擇,這是本人在學(xué)習(xí)jQuery中學(xué)的知識(shí),感覺(jué)很有用,寫(xiě)了下來(lái),希望大家有更好的方法或者代碼不足的地方請(qǐng)諒解,本人也是初學(xué)者啊,希望大家互相勉勵(lì)互相學(xué)習(xí)。2011-04-04Jquery 實(shí)現(xiàn)checkbox全選方法
本文主要向大家展示了一段使用jQuery實(shí)現(xiàn)checkbox全選的方法,以及編寫(xiě)此方法的背景和過(guò)程,非常詳細(xì),這里推薦給小伙伴們。2015-01-01jQuery lazyLoad圖片延遲加載插件的優(yōu)化改造方法分享
jQuery lazyLoad.js插件 是一款基于jquery框架,可以“實(shí)現(xiàn)”圖片延遲加載的插件2013-08-08jQuery實(shí)現(xiàn)的文字hover顏色漸變效果實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的文字hover顏色漸變效果,以完整實(shí)例形式分析了jQuery實(shí)現(xiàn)文字顏色漸變效果的相關(guān)技巧,涉及jQuery插件jquery-ui-1.8.16.custom.min.js的使用,需要的朋友可以參考下2016-02-02jQuery拖動(dòng)布局其結(jié)果保存到數(shù)據(jù)庫(kù)
這篇文章介紹了jQuery實(shí)現(xiàn)拖動(dòng)布局并將排序結(jié)果保存到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方法,感興趣的朋友可以參考一下2015-10-10jquery控制listbox中項(xiàng)的移動(dòng)并排序的實(shí)現(xiàn)代碼
listbox中項(xiàng)的移動(dòng)并排序的jquery實(shí)現(xiàn)代碼,使用jquery與listbox的朋友可以參考下。2010-09-09