SoFunction
Updated on 2025-04-11

Use vue to realize the touch screen sliding function of mobile phone

Function:iview Carousel revolver, I need to implement sliding switching function on my phone.

<div class="phone" @touchstart="phone_mouseS" @touchend="phone_mouseE">
<Carousel :autoplay-speed="5000" v-model="phone_mouseMIndex" autoplay :value="0" loop v-if="menuChoose == '/'">
 <CarouselItem>
 <img class="img" src="../../static/common/phone_banner_index1.jpg" />
 </CarouselItem>
 <CarouselItem>
 <img class="img" src="../../static/common/phone_banner_index1.jpg" />
 </CarouselItem>
 <CarouselItem>
 <img class="img" src="../../static/common/phone_banner_index3.jpg" />
 </CarouselItem>
</Carousel>
</div>
data() {
return {
 phone_mouseMIndex: 0, // Sliding index on the phone phone_mouseMX0: 0, // Sliding index on the phone phone_mouseMX1: 0, // Sliding index on the phone}
},
...
// Slide to start on the phone endphone_mouseS(e){
 this.phone_mouseMX0 = [0].pageX;
},
// The phone ends slidingphone_mouseE(e){
 this.phone_mouseMX1 = [0].pageX;
 let tag = this.phone_mouseMX1 - this.phone_mouseMX0;
 if(tag &gt;= 50){
 if(this.phone_mouseMIndex &gt; 0){
 this.phone_mouseMIndex--;
 }else{
 this.phone_mouseMIndex = 2;
 }
 }
 if(tag &lt;= -50){
 if(this.phone_mouseMIndex &lt; 2){
 this.phone_mouseMIndex++;
 }else{
 this.phone_mouseMIndex = 0;
 }
 }
}

This is the article about using vue to realize the touch screen sliding function of mobile phones. For more related content on touch screen sliding of vue mobile phones, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!