最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

基于jquery可配置循环左右滚动例子_jquery

来源:动视网 责编:小采 时间:2020-11-27 21:00:35
文档

基于jquery可配置循环左右滚动例子_jquery

基于jquery可配置循环左右滚动例子_jquery: 代码如下: 可配置横栏滚动Demo * { margin:0; padding:0;} body { font-size:12px;} #scrollable { background-color:#efefef; border:1px solid #ddd; padding:10px 8px; width:523px; hei
推荐度:
导读基于jquery可配置循环左右滚动例子_jquery: 代码如下: 可配置横栏滚动Demo * { margin:0; padding:0;} body { font-size:12px;} #scrollable { background-color:#efefef; border:1px solid #ddd; padding:10px 8px; width:523px; hei


代码如下:



可配置横栏滚动Demo





(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), //每次滚动的列数,默认为一屏,即父容器列宽
speed = opt.speed ? parseInt(opt.speed, 10) : 500; //滚动速度,数值越大,速度越慢(毫秒)
timer = opt.timer ? parseInt(opt.timer, 10) : 3000; //滚动的时间间隔(毫秒)
if (line == 0) line = 1;
var upWidth = 0 - line * lineW;
//滚动函数
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:自动播放
var autoPlay = function () {
if (timer) timerID = window.setInterval(scrollLeft, timer);
};
var autoStop = function () {
if (timer) window.clearInterval(timerID);
};            //鼠标事件绑定
_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"});
});








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15










说明:1、需要两个图片

left.png:

right.png:

2、需要引入jquery的包,这个应该不用说的...... //

文档

基于jquery可配置循环左右滚动例子_jquery

基于jquery可配置循环左右滚动例子_jquery: 代码如下: 可配置横栏滚动Demo * { margin:0; padding:0;} body { font-size:12px;} #scrollable { background-color:#efefef; border:1px solid #ddd; padding:10px 8px; width:523px; hei
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top