Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  160] [ 6]  / answers: 1 / hits: 38125  / 4 Years ago, thu, july 23, 2020, 12:00:00

I am using this swiper in React:
https://swiperjs.com/react/


I tried to make it "autoplay" but it doesn't auto swipe.
This is what I tried:


// https://swiperjs.com/get-started/
import React from 'react';
import { Swiper, SwiperSlide } from 'swiper/react';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles({
SwiperStyle: {
backgroundColor: '#f5f5f5',
height: '58px',
width: '100%',
},
});

export default function TextInfoSlider(props) {
const classes = useStyles();

return (
<div>

<Swiper
loop={true}
autoplay={{
delay: 500,
disableOnInteraction: false
}}
>

<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
<SwiperSlide>Slide 3</SwiperSlide>
<SwiperSlide>Slide 4</SwiperSlide>

</Swiper>

<style jsx global>{`
.swiper-container {
background-color: #f5f5f5;
}
`}</style>
</div>
)
}

I have also tried to just use boolean on the autoplay but it also doesn't work:


        <Swiper
loop={true}
autoplay={true}
}}
>

More From » reactjs

 Answers
8

By default Swiper React uses core version of Swiper (without any additional components). If you want to use Navitation, Pagination and other components, you have to install them first


It does not seem you have installed Autoplay component.



import SwiperCore, { Autoplay } from 'swiper';
...
SwiperCore.use([Autoplay]);

[#50769] Tuesday, July 14, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shylaelisan

Total Points: 37
Total Questions: 94
Total Answers: 110

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;