资源描述:一款兼容电脑端拖动和手机端滑动的切换特效,主要是利用Swiper库来实现平滑的交互式滑块特效,支持img图片和video视频,类似于短视频平台上下滑动切换视频。
使用方法
//set video duration
const videos = document.querySelectorAll('.story__slide video');
videos.forEach(video => {
$(video).parent('.story__slide').attr('data-swiper-autoplay', video.duration * 1000);
});
const slider = new Swiper(".story__slider", {
speed: 1,
watchSlidesProgress: true,
loop: true,
autoplay: {
delay: 15000,
disableOnInteraction: false
},
slidesPerView: 1,
navigation: {
nextEl: ".story__next",
prevEl: ".story__prev",
},
pagination: {
el: '.story__pagination',
renderBullet: function (index, className) {
return '<div class="' + className + '"> <div class="swiper-pagination-progress"></div> </div>';
}
},
on: {
autoplayTimeLeft(swiper, time, progress) {
let currentSlide = document.querySelectorAll('.story__slider .swiper-slide')[swiper.activeIndex]
let currentBullet = document.querySelectorAll('.story__slider .swiper-pagination-progress')[swiper.realIndex]
let fullTime = currentSlide.dataset.swiperAutoplay ? parseInt(currentSlide.dataset.swiperAutoplay) : swiper.params.autoplay.delay;
let percentage = Math.min( Math.max ( parseFloat(((fullTime - time) * 100 / fullTime).toFixed(1)), 0), 100) + '%';
gsap.set(currentBullet, {width: percentage});
},
transitionEnd(swiper) {
let allBullets = $('.story__slider .swiper-pagination-progress');
let bulletsBefore = allBullets.slice(0, swiper.realIndex);
let bulletsAfter = allBullets.slice(swiper.realIndex, allBullets.length);
if(bulletsBefore.length) {gsap.set(bulletsBefore, {width: '100%'})}
if(bulletsAfter.length) {gsap.set(bulletsAfter, {width: '0%'})}
let activeSlide = document.querySelectorAll('.story__slider .swiper-slide')[swiper.realIndex];
if (activeSlide.querySelector('video')) {
activeSlide.querySelector('video').currentTime = 0;
}
},
}
});
站长提示:
1. 苦力吧素材官方QQ群:
950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励
2K币。
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服