<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<title>keep 里面的上下轮播</title>
<style>
* {
padding: 0;
margin: 0;
}
.page {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: grey;
width: 200px;
height: 180px;
overflow: hidden;
}
.roll-list{
height: 800px;
}
.roll-list li {
list-style: none;
height: 60px;
width: 100%;
}
</style>
</head>
<body>
<div class="page" id="a">
<ul class="roll-list" id="list">
<li class="roll-item" style="background-color: hotpink">1</li>
<li class="roll-item" style="background-color:lawngreen">2</li>
<li class="roll-item" style="background-color:midnightblue">3</li>
<li class="roll-item" style="background-color: rgb(255, 185, 105)">4</li>
</div>
</body>
<script>
let item = document.getElementsByClassName('roll-item');
let itemWidth = item[0].offsetHeight;
function autoScroll(obj) {
$(obj).find("ul").animate({
marginTop: `-${itemWidth}px`
}, 1000, function () {
$(this).css({ marginTop: "0px"}).find("li:first").appendTo(this);
})
}
$(function () {
var scroll = setInterval('autoScroll(".page")', 2000);
$(".page").hover(function () {
clearInterval(scroll);
}, function () {
scroll = setInterval('autoScroll(".page")', 2000);
});
});
</script>
</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
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