如何解决滑动滑块效果在React Js中不起作用
我正在使用React Js和Swiper Js来获得与LInk中相同的效果。但是由于某种原因,我无法在其中实现任何效果或分页。
我的组件文件夹中有Card.js:
import React from 'react';
import 'swiper/swiper-bundle.js'
import 'swiper/swiper-bundle.min.js'
import 'swiper/swiper-bundle.css';
import 'swiper/swiper-bundle.min.css';
import './Card.css';
import Swiper from 'swiper';
class Card extends React.Component{
componentDidMount(){
var swiper = new Swiper('.swiper-container',{
pagination: '.swiper-pagination',effect: 'coverflow',grabCursor: true,centeredSlides: true,slidesPerView: 'auto',coverflow: {
rotate: 50,stretch: 0,depth: 100,modifier: 1,slideShadows : true
},loop: true
});
}
render(){
return(
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide"><img src="http://lorempixel.com/600/600/nature/1"/></div>
<div class="swiper-slide"><img src="http://lorempixel.com/600/600/nature/2"/></div>
<div class="swiper-slide"><img src="http://lorempixel.com/600/600/nature/3"/></div>
</div>
<div class="swiper-pagination"></div>
</div>
);
}
}
export default Card
我尝试使用this.swiper进行初始化,但仍然没有锻炼。
我的CSS有:
body {
background: #fff;
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 14px;
color:#000;
margin: 0;
padding: 0;
}
.swiper-container {
width: 100%;
padding-top: 50px;
padding-bottom: 50px;
}
.swiper-slide {
background-position: center;
background-size: cover;
width: 300px;
height: 300px;
}
它仅在彼此相邻的图像上以幻灯片形式出现,而没有应用任何效果。.滑动时没有Coverflow效果。 我错过任何进口商品还是做错了什么。谁能帮我解决这个问题。
在独立的html页面中效果很好。
解决方法
您应该使用NPM软件包swiper
而不是普通的JS版本。实现目标所需的一切都在this page
请记住-“默认情况下,Swiper React使用的是Swiper的核心版本(没有任何其他组件)。如果要使用导航,分页和其他组件,则必须先安装它们。”
要安装非核心组件,请执行以下操作:
SwiperCore.use([Navigation,Pagination,Scrollbar,A11y]);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。