-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlunbo.html
168 lines (164 loc) · 6.54 KB
/
lunbo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>滚动插件</title>
<!-- Bootstrap -->
<link href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="http://cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
<!--[if IE 7]>
<link rel="stylesheet" href="http://cdn.bootcss.com/font-awesome/3.2.1/css/font-awesome-ie7.min.css">
<![endif]-->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="http://cdn.bootcss.com/jquery/2.1.3/jquery.min.js"></script>
<style type="text/css">
.lunbo1 { }
</style>
</head>
<body>
<div class="container">
<h1>影藏/显示</h1>
<div class="lunbo1" role="listbox">
<ul class="list-unstyled">
<li><img src="https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=88c2e98e64d9f2d3204477afcfd1be21/80cb39dbb6fd52662320ea7bad18972bd4073652.jpg"></li>
<li><img src="https://ss3.baidu.com/-fo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=bbee48a445166d22382246d4201e3dc5/d043ad4bd11373f06c17a0f0a20f4bfbfbed04b1.jpg"></li>
<li><img src="https://ss1.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=6a420e7b6d600c33f02c8d887c71653d/eac4b74543a98226cedde6488c82b9014a90eb45.jpg"></li>
</ul>
</div>
<a class="pre" href="javascript:;">上一位</a>
<a class="run" href="javascript:;">开始</a>
<a class="stop" href="javascript:;">停止</a>
<a class="next" href="javascript:;">下一位</a>
<h1>滚动</h1>
<div class="row scroll-box">
<ul class="list-group col-md-3">
<li class="list-group-item">11111</li>
<li class="list-group-item">22222</li>
<li class="list-group-item">33333</li>
<li class="list-group-item">44444</li>
<li class="list-group-item">55555</li>
<li class="list-group-item">66666</li>
<li class="list-group-item">77777</li>
<li class="list-group-item">88888</li>
<li class="list-group-item">99999</li>
<li class="list-group-item">10101</li>
<li class="list-group-item">11111</li>
<li class="list-group-item">12121</li>
</ul>
</div>
</div>
<script type="text/javascript">
$(function(){
$('.lunbo1 ul li').hide();
$('.lunbo1 ul li').eq(0).show();
var lb = scroller2('.lunbo1', 1500);
lb.run();
$('a.pre').click(function(){
lb.pre();
});
$('a.next').click(function(){
lb.next();
});
$('a.stop').click(function(){
lb.stop();
});
$('a.run').click(function(){
lb.run();
});
});
/**
* [scroller2 显示影藏轮播]
* @param {[type]} tab [description]
* @param {[type]} sec [description]
* @return {[type]} [description]
*/
function scroller2(tab, sec){
var obj = new Object(); //创建一个对象
obj.tag = $(tab+' ul li'); //对象tag属性赋值 html元素对象
obj.sec = sec; //对象sec属性接收传入的sec值
obj.t = null; //对象t默认空,后面赋值定时对象
obj.ind = 0; //对象ind, 后面赋值当前显示元素下标
obj.init = function(){ //对象init方法初始化下标值
for (var i = obj.tag.length - 1; i >= 0; i--) {
if($(obj.tag).eq(i).css('display')!=='none'){
obj.ind = i; break;
}
}
},
obj.run = function(){ //对象run方法执行定时任务
obj.init();
if(!obj.t)
obj.t = setInterval(function(){ obj.next(); }, obj.sec);
},
obj.stop = function(){ //对象stop方法执行停止任务
clearInterval(obj.t);
obj.t = null;
},
obj.next = function(){ //对象next方法执行往后切换显示与影藏
obj.stop();
obj.ind = obj.ind + 1 > $(obj.tag).length -1 ? 0 : obj.ind + 1;
$(obj.tag).hide();
$(obj.tag).eq(obj.ind).show();
obj.run();
},
obj.pre = function(){ //对象pre方法执行往前切换显示与影藏
obj.stop();
obj.ind = obj.ind - 1 < 0 ? $(obj.tag).length -1 : obj.ind - 1;
$(obj.tag).hide();
$(obj.tag).eq(obj.ind).show();
obj.run();
}
return obj; //返回对象
}
/**
* [scroller 滚动JS]
* @param {[type]} tag [标签]
* @param {[type]} sec [执行间隔时间秒]
* @return {[type]} [description]
*/
function scroller(tag, sec){
var obj = new Object();
obj.offsetHeiht = 0; //偏移距离适当补偿
obj.sec = sec; //执行间隔时间秒
obj.t = null;
obj.init = function(){
var li_height = $(tag).children('ul').children('li').eq(0).innerHeight();
obj.offsetHeiht = li_height + 1; //1px边框适当调整
$(tag).children('ul').mouseover(function(){ //鼠标移入停止动画
clearInterval(obj.t);
}).mouseout(function(){
obj.t = setInterval(function(){ obj.move(); }, obj.sec);
});
}
obj.run = function(){
obj.init(); obj.move();
obj.t = setInterval(function(){ obj.move(); }, obj.sec);
}
obj.crop = function(){
var html = $(tag).children('ul').children('li').eq(0);
$(tag).children('ul').children('li').eq(0).remove();
$(tag).children('ul').append(html);
$(tag).children('ul').css('top', '0');
}
obj.move = function(){
$(tag).children('ul').animate({top: "-"+obj.offsetHeiht+"px"}, obj.sec, 'linear', function(){ obj.crop(); });
}
return obj;
}
$(function(){
scroller('.scroll-box', 1000).run();
});
</script>
<!-- Scripts -->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</body>
</html>