Vue-Awesome-Swiper为slide绑定@click事件

举例需要点击图片达到放大的效果

如图:

轮播效果

点击放大效果

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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<template>
<div>
<div
v-swiper:mySwiper="swiperOption"
class="swiper-container"
>
<div class="swiper-wrapper">
<div
v-for="item in data" //prop传过来的值,用来循环
:key="item.key"
class="swiper-slide"
:data_index="item.pic" //注意这里,要将这个图片地址传给下面的显示大图的div
>
<div class="title">{{ item.title }}</div>
<img :data-src="item.pic" class="swiper-lazy"> //懒加载图片
<div class="swiper-lazy-preloader" /> //懒加载效果
</div>
</div>
<div class="swiper-pagination" /> //页码
<div class="swiper-button-prev"><svg-icon iconclass="left" /></div> //向左翻
<div class="swiper-button-next"><svg-icon iconclass="right" /></div>
</div>
<div class="showImgBg" :style="{'display':isAcitve}" @click="thsClose">//点击显示大图的div
<div class="showImg">
<img
:src="isshowImg"//传过来的图片地址
/>
</div>
</div>
</div>
</template>

<script>
export default {
name: 'Swiper',
props: {
data: { //作为组件得到的数据
type: Array,
required: true
}
},
data() {
return {
isAcitve: 'none', //控制显隐
isshowImg: '',//传过来的图片地址
swiperOption: { //swiper参数官网自行脑部
autoplay: {
delay: 5000,
disableOnInteraction: false
},
speed: 700,
allowTouchMove: false,
lazy: {
loadPrevNext: true,
loadPrevNextAmount: 3
},
centeredSlides: true,
spaceBetween: 50,
slidesOffsetBefore: 40,
loop: true,
slidesPerView: 4,
on: {
slideChangeTransitionEnd: function() {
this.slides.transition(this.params.autoplay.delay + this.params.speed).transform('translate3d(-60px, 0, 0)')
},
slideChangeTransitionStart: function() {
this.slides.transition(this.params.speed).transform('translate3d(0, 0, 0)')
}
},
pagination: {
el: '.swiper-pagination',
clickable: true,
renderBullet: function(index, className) {
return '<div class="' + className + '"><span></span><i></i></div>'
}
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev'
}
}
}
},
mounted() {
this.mySwiper.slideTo(2, 1000, false)
//*****这一段是重点*****
const _this = this
this.mySwiper.on('tap', function() { //为轮播绑定 methods 中的方法 toSonControl,并获取我们之前绑定的 data_index 的值
_this.toSonControl(this.clickedSlide.getAttribute('data_index'))
})
},
methods: {
toSonControl(img) { //显隐操作
this.isAcitve = 'block'
this.isshowImg = img
console.log(img)
},
thsClose() {
this.isAcitve = 'none'
},
showImg(img) {
this.isAcitve = 'block'
this.isshowImg = img
console.log(img)
}
}
}
</script>

<style>
.showImgBg{
position: fixed;
top:0;
left:0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index:1000;
}
.showImg{
max-width: 1000px;
max-height: 90%;
overflow-y:scroll;
margin: 0 auto;
margin-top:30px;
}
.showImg img{
width: 100%
}
.swiper-container {
padding-bottom: 40px;
}
.swiper-slide {
width: 978px;
transition-timing-function: linear;
}
@media only screen and (max-width: 1200px) {
.swiper-slide {
width: 770px;
}
}
@media only screen and (max-width: 980px) {
.swiper-slide {
width: 471px;
}
}
@media only screen and (max-height: 480px) {
.swiper-slide {
width: 471px;
}
}
.swiper-slide img {
width: 100%;
border-radius: 4px;
}
.swiper-slide .title {
position: absolute;
transform: rotate(90deg);
transform-origin: left top;
left: -3px;
font-size: 11px;
color: rgb(102, 102, 102);
}
.swiper-button-next,
.swiper-button-prev {
top: 50%;
background-color: rgba(210, 210, 210, 0.6);
background-size: 15px 15px;
border-radius: 50%;
width: 52px;
height: 52px;
line-height: 52px;
text-align: center;
color: #26824c;
transition: all 0.5s;
outline: none;
background-image:none!important;
}
.mouse-hover .swiper-button-next,
.mouse-hover .swiper-button-prev {
opacity: 0.5;
}
.swiper-button-next:hover,
.swiper-button-prev:hover {
background-color: rgba(210, 210, 210, 0.8);
}
.swiper-button-next {
right: 20px;
}
.swiper-button-prev {
left: 20px;
}
.swiper-container .swiper-button-next.swiper-button-disabled,
.swiper-container .swiper-button-prev.swiper-button-disabled {
opacity: 1;
}
.swiper1-button-next,
.swiper1-button-prev {
position: absolute;
margin-top:-210px;
width: 86px;
height: 112px;
background-size: 86px 112px;
outline: none;
cursor: pointer;
}
.swiper1-button-next {
right:200px;
left:auto;
background-image: url(/cursor-next.png);
}
.swiper1-button-prev {
left:200px;
right:auto;
background-image: url(/cursor-prev.png);
}
.swiper-pagination-bullet {
background: none;
opacity: 1;
margin: 0 6px !important;
width: 9px;
height: 9px;
position: relative;
outline: none;
vertical-align: middle;
}
.swiper-pagination-bullet span {
width: 3px;
height: 3px;
background: #ccc;
display: block;
border-radius: 50%;
margin-top: 3px;
margin-left: 3px;
}
.swiper-pagination-bullet i {
background: #26824c;
height: 1px;
width: 20px;
position: absolute;
top: 4px;
transform: scaleX(0);
transform-origin: left;
z-index: 3;
transition-timing-function: linear;
}
.swiper-pagination-bullet-active span,
.swiper-pagination-bullet:hover span {
width: 9px;
height: 9px;
margin-top: 0;
margin-left: 0;
background: #26824c;
position: relative;
z-index: 1;
}
.swiper-pagination-bullet-active i {
animation: middle 6s;
}
.swiper-pagination-bullet:first-child.swiper-pagination-bullet-active i {
animation: first 6s;
}
.swiper-pagination-bullet:last-child.swiper-pagination-bullet-active i {
animation: last 6s;
}
@keyframes first {
0% {
transform: scaleX(0.5);
left: 0px;
} /*091*/
100% {
transform: scaleX(1);
left: 2px;
} /*0915*/
}
@keyframes last {
0% {
transform: scaleX(0.7);
left: -10px;
} /*1090*/
20% {
transform: scaleX(0.3);
left: 2px;
} /*090*/
100% {
transform: scaleX(0.3);
left: 0px;
} /*090*/
}
@keyframes middle {
0% {
transform: scaleX(0.7);
left: -10px;
} /*1091*/
20% {
transform: scaleX(0.45);
left: 2px;
} /*092*/
100% {
transform: scaleX(1);
left: 2px;
} /*0913*/
}
</style>

当要查询ID为42的连载漫画中的章节并排序时

使用以下sql语句

1
2

SELECT * FROM `漫画章节表` WHERE `连载漫画ID` = 42 ORDER BY `id` DESC

看似没有问题,但当数据量过大,连载漫画更新频率很长 “漫画章节表” 中的数据就会变成这样

1
2
3
4
5
6
7
8
9
10
11
id    ... manhua_id

1 ... 42
2 ... 42
.... //其他数据
52013 ... 42
52014 ... 42
.... //其他数据
120391 ... 42
120392 ... 42
.... //其他数据

相同漫画下的章节id跨度很大 使用 “ORDER” 进行排序,就会非常非常的耗费性能

目前解决办法有两种(欢迎投稿留言,分享更好的解决办法)

1.添加”order”字段 查询的数据按照该字段排序

1
2
3
4
5
6
7
8
9
10
11
id    ... manhua_id

1 ... 42 //添加order字段:order=1
2 ... 42 //添加order字段:order=2
.... //其他数据
52013 ... 42 //添加order字段:order=3
52014 ... 42 //添加order字段:order=4
.... //其他数据
120391 ... 42 //添加order字段:order=5
120392 ... 42//添加order字段:order=6
.... //其他数据

2.只查询不排序,拿到数据之后在客户端用页面脚本排序

# ,

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×