Videojs+swiper realizes Taobao product details carousel

Videojs+swiper realizes Taobao product details carousel

This article shares the specific code of videojs+swiper to realize the carousel of Taobao product details for your reference. The specific content is as follows

This one references videojs and swiper. The effect is similar to the carousel pictures in Taobao product details, and the first carousel is a video:
When the video starts playing, the carousel stops. When the video is paused, the carousel continues.
When the video is playing, when you slide to the next slide, the video will pause.

swiper manual

HTML part:

<!-- swiper carousel-->
<div class="swiper-container">
   <div class="swiper-wrapper">
       <div class="swiper-slide">
           <video id="video" style="width: 100%;height: 100%;" controls preload="none" poster="xxxx" class="video-js vjs-big-play-centered" >
            <source src="xxxx" type="video/mp4">
           </video>
       </div>
       <div class="swiper-slide"><img src="xxxx" alt=""></div>
        <div class="swiper-slide"><img src="xxxx" alt=""></div>
        <div class="swiper-slide"><img src="xxxx" alt=""></div>
        <div class="swiper-slide"><img src="xxxx" alt=""></div>
   </div>
   <!-- If you need a pager -->
   <div class="swiper-pagination"></div>
</div>

js part:

//Create a new videojs object var player = videojs('video', {
     muted: true,
     controls: true,
     // loop: true,
 });

 // swiper carousel var mySwiper = new Swiper ('.swiper-container', {
     direction:'horizontal', // The direction of the slideshow, can also be vertical loop: true, // loop play autoplay:3000, // slide automatic switching time speed:2000, // slide sliding animation time height: 100,
     pagination: '.swiper-pagination', // If you need a paginator, that is, the small dot below autoplayDisableOnInteraction : false, // In this way, even if we slide, the timer will not be cleared offsetWidth: 0,
     observer:true, //Monitor // When swiper transitions from one slide to another, execute: stop video playback (here is swiper3, swiper4 is written differently)
     onSlideChangeStart: function(swiper){
          player.pause();
     }
 });


 //Stop the carousel while the video is playingplayer.on('play',function(){
     // console.log(mySwiper)
     mySwiper.stopAutoplay()
 });

 // When the video is paused, the carousel continues player.on('pause', function(){
     mySwiper.startAutoplay()
 });

The js and css of swiper and videojs are not introduced here, you can search them on Baidu.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • JavaScript to achieve Taobao product image switching effect
  • javascript to realize product image magnifying glass
  • JavaScript implements product details of e-commerce platform

<<:  How to delete garbled or special character files in Linux

>>:  MySQL Order By Multi-Field Sorting Rules Code Example

Recommend

How to create a view in MySQL

Basic syntax You can create a view using the CREA...

A brief discussion on the differences between FTP, FTPS and SFTP

Table of contents Introduction to FTP, FTPS and S...

Docker View the Mount Directory Operation of the Container

Only display Docker container mount directory inf...

Code comment writing standards during web page production

<br />I have summarized the annotation writi...

Solution to the impact of empty paths on page performance

A few days ago, I saw a post shared by Yu Bo on G...

Tutorial on processing static resources in Tomcat

Preface All requests in Tomcat are handled by Ser...

Native JS to implement paging click control

This is an interview question, which requires the...

How to use not in to optimize MySql

Recently, when using select query in a project, I...

How to ensure the overall user experience

Related Articles: Website Design for User Experien...

Detailed explanation of the difference between run/cmd/entrypoint in docker

In Dockerfile, run, cmd, and entrypoint can all b...

How to start a Vue.js project

Table of contents 1. Node.js and Vue 2. Run the f...

Understanding innerHTML

<br />Related articles: innerHTML HTML DOM i...