踩坑,新版swiper在ant design pro 或react组件中autoplay不起作用的更正设置方法

本文主要是介绍踩坑,新版swiper在ant design pro 或react组件中autoplay不起作用的更正设置方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

swiper一直更新是个好事,但使用方法一直在悄悄的变,真得很坑人,直接带过坑吧。

关键在这个引入这里,新版的必须将Autoplay作为模块引入,反正和以前版本有很多不一样了。 

import { Autoplay, EffectFade, Pagination, Navigation } from 'swiper/modules';
import { Swiper, SwiperSlide } from 'swiper/react';
// Import Swiper styles
import 'swiper/css';
import 'swiper/css/pagination';
import 'swiper/css/navigation';
import 'swiper/css/effect-fade';

接下来是组件中引入

<SwipperWrapper ><SwiperspaceBetween={30}effect={'fade'}// slidesPerView={3}centeredSlides={true}navigation={true}pagination={{clickable: true,}}modules={[EffectFade,Autoplay,Navigation,Pagination]}autoplay={{delay: 3000,disableOnInteraction: false,}}loop>{slideList?.map(itm => {return (<SwiperSlide key={itm.id}><img src={`${itm.img}`} alt={itm.title} /></SwiperSlide>)})}</Swiper>
</SwipperWrapper>

再根据demo设置自定义样式,这个不是必须的了,只是图片等更合理的一些设置而已,可以自己定义:

export const SwipperWrapper = styled.div`margin-top:3rem;.swiper {width: 100%;height: 100%;}.swiper-slide {background-position: center;background-size: cover;}.swiper-slide img {display: block;width: 100%;}
`;

其他说明,新版本的swiper在react中基本上都是以模块或组件引入了,如果有些效果不起作用,说明你得使用方法和对应版本可能不一样,重新根据官网版本安装指定版本或自己找对应版本的demo再进行设置。

下面是自己需要用到的样式,需要那个就必须应用对应的样式,注意这个与低版本的路径也不一样了。

Styles

Swiper package contains different sets of CSS, Less and SCSS styles:

  • swiper/css - only core Swiper styles
  • swiper/css/bundle - all Swiper styles including all modules styles (like Navigation, Pagination, etc.)

Modules styles (not required if you already imported bundle styles):

  • swiper/css/a11y - styles required for A11y module
  • swiper/css/autoplay - styles required for Autoplay module
  • swiper/css/controller - styles required for Controller module
  • swiper/css/effect-cards - styles required for Cards Effect module
  • swiper/css/effect-coverflow - styles required for Coverflow Effect module
  • swiper/css/effect-creative - styles required for Creative Effect module
  • swiper/css/effect-cube - styles required for Cube Effect module
  • swiper/css/effect-fade - styles required for Fade Effect module
  • swiper/css/effect-flip - styles required for Flip Effect module
  • swiper/css/free-mode - styles required for Free Mode module
  • swiper/css/grid - styles required for Grid module
  • swiper/css/hash-navigation - styles required for Hash Navigation module
  • swiper/css/history - styles required for History module
  • swiper/css/keyboard - styles required for Keyboard module
  • swiper/css/manipulation - styles required for Manipulation module
  • swiper/css/mousewheel - styles required for Mousewheel module
  • swiper/css/navigation - styles required for Navigation module
  • swiper/css/pagination - styles required for Pagination module
  • swiper/css/parallax - styles required for Parallax module
  • swiper/css/scrollbar - styles required for Scrollbar module
  • swiper/css/thumbs - styles required for Thumbs module
  • swiper/css/virtual - styles required for Virtual module
  • swiper/css/zoom - styles required for Zoom module

这篇关于踩坑,新版swiper在ant design pro 或react组件中autoplay不起作用的更正设置方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/651656

相关文章

使用国内镜像源优化pip install下载的方法步骤

《使用国内镜像源优化pipinstall下载的方法步骤》在Python开发中,pip是一个不可或缺的工具,用于安装和管理Python包,然而,由于默认的PyPI服务器位于国外,国内用户在安装依赖时可... 目录引言1. 为什么需要国内镜像源?2. 常用的国内镜像源3. 临时使用国内镜像源4. 永久配置国内镜

Mybatis从3.4.0版本到3.5.7版本的迭代方法实现

《Mybatis从3.4.0版本到3.5.7版本的迭代方法实现》本文主要介绍了Mybatis从3.4.0版本到3.5.7版本的迭代方法实现,包括主要的功能增强、不兼容的更改和修复的错误,具有一定的参考... 目录一、3.4.01、主要的功能增强2、selectCursor example3、不兼容的更改二、

VSCode中C/C++编码乱码问题的两种解决方法

《VSCode中C/C++编码乱码问题的两种解决方法》在中国地区,Windows系统中的cmd和PowerShell默认编码是GBK,但VSCode默认使用UTF-8编码,这种编码不一致会导致在VSC... 目录问题方法一:通过 Code Runner 插件调整编码配置步骤方法二:在 PowerShell

C/C++随机数生成的五种方法

《C/C++随机数生成的五种方法》C++作为一种古老的编程语言,其随机数生成的方法已经经历了多次的变革,早期的C++版本使用的是rand()函数和RAND_MAX常量,这种方法虽然简单,但并不总是提供... 目录C/C++ 随机数生成方法1. 使用 rand() 和 srand()2. 使用 <random

QT移植到RK3568开发板的方法步骤

《QT移植到RK3568开发板的方法步骤》本文主要介绍了QT移植到RK3568开发板的方法步骤,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录前言一、获取SDK1. 安装依赖2. 获取SDK资源包3. SDK工程目录介绍4. 获取补丁包二

Java反转字符串的五种方法总结

《Java反转字符串的五种方法总结》:本文主要介绍五种在Java中反转字符串的方法,包括使用StringBuilder的reverse()方法、字符数组、自定义StringBuilder方法、直接... 目录前言方法一:使用StringBuilder的reverse()方法方法二:使用字符数组方法三:使用自

Ubuntu中Nginx虚拟主机设置的项目实践

《Ubuntu中Nginx虚拟主机设置的项目实践》通过配置虚拟主机,可以在同一台服务器上运行多个独立的网站,本文主要介绍了Ubuntu中Nginx虚拟主机设置的项目实践,具有一定的参考价值,感兴趣的可... 目录简介安装 Nginx创建虚拟主机1. 创建网站目录2. 创建默认索引文件3. 配置 Nginx4

java导出pdf文件的详细实现方法

《java导出pdf文件的详细实现方法》:本文主要介绍java导出pdf文件的详细实现方法,包括制作模板、获取中文字体文件、实现后端服务以及前端发起请求并生成下载链接,需要的朋友可以参考下... 目录使用注意点包含内容1、制作pdf模板2、获取pdf导出中文需要的文件3、实现4、前端发起请求并生成下载链接使

kotlin中的行为组件及高级用法

《kotlin中的行为组件及高级用法》Jetpack中的四大行为组件:WorkManager、DataBinding、Coroutines和Lifecycle,分别解决了后台任务调度、数据驱动UI、异... 目录WorkManager工作原理最佳实践Data Binding工作原理进阶技巧Coroutine

Linux虚拟机不显示IP地址的解决方法(亲测有效)

《Linux虚拟机不显示IP地址的解决方法(亲测有效)》本文主要介绍了通过VMware新装的Linux系统没有IP地址的解决方法,主要步骤包括:关闭虚拟机、打开VM虚拟网络编辑器、还原VMnet8或修... 目录前言步骤0.问题情况1.关闭虚拟机2.China编程打开VM虚拟网络编辑器3.1 方法一:点击还原VM