当前位置:网站首页>Swiper4 is used to smooth longitudinal seamless scrolling. After clicking or dragging the mouse, the animation is not completely completed, the mouse moves out of the automatic rotation, and the dynam
Swiper4 is used to smooth longitudinal seamless scrolling. After clicking or dragging the mouse, the animation is not completely completed, the mouse moves out of the automatic rotation, and the dynam
2022-07-25 03:02:00 【cc_ King】
Use swiper4 Smooth longitudinal seamless rolling , Click or drag the mouse , The animation is not complete , Mouse removal Automatic rotation failure
List of articles
Every time I encounter some tricky problems , Then Baidu solved it , All you meet are pasted and copied 、 Allied , It's over and can't be solved , I really feel very tired ....
First summarize what you found on the Internet
disableOnInteraction: Whether to prohibit after user operation autoplay( The default value is : true: prohibit );
speed: 2000,
autoplay: {
delay: 2500,
disableOnInteraction: false,
}
One thing to note here : autoplay.delay The value of must be greater than speed, Otherwise, it's useless
autoPalyDisableOnInteraction: This logic is consistent with the first one above , It's just that this is v3 edition ,disableOnInteractionyes v4 And later ,
autoPalyDisableOnInteraction: false,
autoplay: {
...
}
- Define your own
onmouseevent
mySwiper.el.onmouseover = function(){
mySwiper.autoplay.stop();
}
mySwiper.el.onmouseout = function(){
mySwiper.autoplay.start();
}
pauseOnMouseEnter: The most convenient , There will be no problem , But enable version :6.6.2…
autoplay: {
pauseOnMouseEnter: true,
}
So here comes the question ,v4 edition , also delay:0, None of the above can be used ...
Then make one by yourself
Finally, we can only combine api Make a pause by yourself , annoying
The main thing is to combine transitionEnd & slideNext ;
When the current transition is complete , Switch to the next one immediately ;
Don't talk much , Post the final code directly :
<template>
<div class='swiper-page'>
<div class="swiper" id="swiper" ref="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="item in 20" :key="item" :style="{backgroundColor: colorList[item % colorList.length]}"> slide-item {
{
item }}</div>
</div>
</div>
</div>
</template>
<script>
import Swiper from 'swiper';
export default {
data() {
return {
swiperIns: null,
swiperPause: false, // Rotation pause
colorList: ['#FC88A6', '#F7A753', '#3F8EFA', '#33D260', '#6AC1E1'],
};
},
mounted() {
this.$nextTick(_ => {
// Before each instantiation , Destroy the previous instance , Prevent animation disorder
if (this.swiperIns) {
this.swiperIns.destroy();
}
this.swiperIns = new Swiper("#swiper", {
speed: 2000,
direction: 'vertical',
height: 80,// Not used here slidesPerView Automatic calculation , Otherwise, problems may occur during initialization
loop: true,
loopAdditionalSlides: 5,
preventLinksPropagation: true,
on: {
transitionEnd: () => {
// Try to jump to the next one after the transition
this.swiperAutoPlay();
}
}
});
this.swiperAutoPlay(); // You need to manually start the first jump
this.$refs.swiper.onmouseenter = () => {
this.swiperPause = true;
};
this.$refs.swiper.onmouseleave = () => {
// To restart the rotation, you need to set the following two data
this.swiperPause = false;
this.swiperAutoPlay();
}
});
},
methods: {
// Try playing the next
swiperAutoPlay() {
this.$nextTick(_ => {
if (this.swiperPause === false) {
this.swiperIns.slideNext();
}
})
},
}
};
</script>
<style lang='scss' scoped>
.swiper-page {
#swiper {
margin: 200px auto 0px;
width: 500px;
height: 400px;
box-sizing: border-box;
border: 1px solid #ccc;
overflow: hidden;
.swiper-wrapper {
transition-timing-function: linear;
}
.swiper-slide {
width: 100%;
height: 80px;
line-height: 80px;
font-size: 30px;
text-align: center;
color: #ccc;
box-sizing: border-box;
border: 1px solid #ccc;
}
}
}
</style>
边栏推荐
- JS foundation -- task queue and event loop
- Domain driven model (DDD)
- Web -- JDBC tool class writing
- JS written test question -- browser kernel
- Method of adding kernel in Jupiter notebook
- Wechat H5 record
- [jailhouse article] scheduling policies and system software architectures for mixed criticality
- Banana pie bpi-m5 toss record (3) -- compile BSP
- JS construction linked list
- Dc-2-range practice
猜你喜欢

6.0 cancellation of member registration verification code

Hashcode details

Ctfshow misc introduction

Reasons for not sending requests after uni app packaging

SQL Server 2022 installation

Tp5.1 include include files (reference public files)

JS written test questions -- random numbers, array de duplication

Review all frames before sum of SSM frames

Learning Record V

Learning record Xi
随机推荐
The latest interview questions and analysis of software testing in 2022
Color space (1) - RGB
Reasons for not sending requests after uni app packaging
Sequence diagram of UML diagram series
mysql_ Master slave synchronization_ Show slave status details
# CF #808 Div.2(A - C)
mysql_ Create temporary table
Learning record Xi
Mark down learning
Pypi counts the number of Downloads
Can bus baud rate setting of stm32cubemx
Tp5.0 background admin access
Matlab for circular pit
Jenkins plug-in development -- plug-in expansion
JS written test question -- promise, setTimeout, task queue comprehensive question
Mid year summary and personal feelings
Innobackupex parameter description
JS written test question -- realize the flat function of array
Concurrent programming day01
Wechat sports field reservation of the finished works of the applet graduation project (7) mid-term inspection report