-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue轮播图.html
135 lines (119 loc) · 3.37 KB
/
vue轮播图.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>v轮播图</title>
<style lang="">
* {
margin: 0;
padding: 0;
list-style: none;
}
.clearfix {
content: '';
clear: both;
display: block;
}
.carousel {
width: 500px;
height: 300px;
margin: 0 auto;
overflow: hidden;
position: relative;
}
.slide {
width: 500px;
height: 300px;
}
li {
position: absolute
}
img {
width: 500px;
height: 300px;
}
.bullet {
width: 100%;
position: absolute;
bottom: 10px;
margin: 0 auto;
text-align: center;
z-index: 10;
}
span {
width: 20px;
height: 5px;
border: 1px solid;
background: white;
display: inline-block;
margin-right: 10px;
}
.active {
background: red;
}
.image-enter-active {
transform: translateX(0);
transition: all 1s ease;
}
.image-leave-active {
transform: translateX(-100%);
transition: all 1s ease;
}
.image-enter {
transform: translateX(100%)
}
.image-leave {
transform: translateX(0)
}
</style>
<script src='https://unpkg.com/vue'>
</script>
</head>
<body>
<div class="carousel">
<transition-group tag='ul' class="clearfix slide" name='image'>
<li v-for='(image,index) in img' :key='index' v-show='index===mark'>
<a>
<img :src="image">
</a>
</li>
</transition-group>
<div class="bullet">
<span v-for='(item,index) in img.length' :class="{'active':index===mark}" @click='change(index)'></span>
</div>
</div>
<script>
new Vue({
el: '.carousel',
data: {
mark: 0,
timer: null,
img: [
'http://upload-images.jianshu.io/upload_images/3360875-5625658440cb542d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240',
'http://upload-images.jianshu.io/upload_images/3360875-b70e9d81d26e2a27.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240',
'http://upload-images.jianshu.io/upload_images/3360875-dc724649454c2ddc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240',
'http://upload-images.jianshu.io/upload_images/3360875-d2148a1bb7ea9d21.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240'
]
},
created() {
this.play()
},
methods: {
change(i) {
this.mark = i
},
autoPlay() {
this.mark++
if (this.mark === 4) {
this.mark = 0
return
}
},
play() {
setInterval(this.autoPlay, 3000)
}
}
})
</script>
</body>
</html>