-
Notifications
You must be signed in to change notification settings - Fork 0
/
rolling.html
90 lines (89 loc) · 2.34 KB
/
rolling.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
ul,li,a{margin:0;padding:0;}
a{color:#fff}
li{list-style:none;text-align:center;}
#t{overflow:hidden;position:relative;width:100%;height:100px;margin:0 auto;background:#ddd;}
#t ul{overflow:hidden;width:325%;position:absolute;top:25px;left:-20%}
#t li{width:6%;height:50px;background:#000;float:left;margin-left:22px;line-height:50px;}
#t li:first-child{margin-left:0;}
.btns{width:100%;margin:20px auto;text-align:center}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var li_ele = $("#t li");
var li_w = $("#t li").width()+22;
var leftGo = "-=";
var rightGo = "+="
var infinite;
var rolling;
//auto play
function loopObj(behavior) {
infinite = setInterval(function(){
$("#t ul").animate({
left:behavior+li_w,
},"slow",function(){
var frst = $("#t ul li:first-child")
$("#t ul").append(frst)
$("#t ul").css("left","-20%");
});
},1000);
}
function loopObj2(behavior,btns) {
rolling = setTimeout(function(){
$("#t ul").animate({
left:behavior+li_w,
},"fast",function(){
var frst = $("#t ul li:first-child");
var last = $("#t ul li:last-child");
if (btns == "next") {
$("#t ul").append(frst)
}
if (btns == "prev") {
$("#t ul").prepend(last)
}
$("#t ul").css("left","-20%");
});
},100);
}
loopObj(leftGo)
//custom play
$("button").click(function(){
var btns = $(this).text();
switch (btns) {
case "prev" : clearInterval(infinite); loopObj2(rightGo,btns);break;
case "next" : clearInterval(infinite); loopObj2(leftGo,btns);break;
case "auto" : clearInterval(infinite); loopObj(leftGo); break;
case "stop" : clearInterval(infinite); break;
}
})
})
</script>
</head>
<body>
<div id="t">
<ul>
<li><a href="#">obj1</a></li>
<li><a href="#">obj2</a></li>
<li><a href="#">obj3</a></li>
<li><a href="#">obj4</a></li>
<li><a href="#">obj5</a></li>
<li><a href="#">obj6</a></li>
<li><a href="#">obj7</a></li>
<li><a href="#">obj8</a></li>
<li><a href="#">obj9</a></li>
<li><a href="#">obj10</a></li>
</ul>
</div>
<div class="btns">
<button type="button">prev</button>
<button type="button">next</button>
<button type="button">auto</button>
<button type="button">stop</button>
</div>
</body>
</html>