I´m using swiper to make a slider on my website. Unfortunately the navigation isn´t working in Chrome.. The buttons appear but don´t do anything.
This is my code:
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
</div>
<div class="swiper-slide">
</div>
<div class="swiper-slide">
</div>
<div class="swiper-slide">
</div>
<div class="swiper-slide">
</div>
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
<script src="js/swiper/swiper.min.js"></script>
<script>
var swiper = new Swiper('.swiper-container', {
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
slidesPerView: 3,
spaceBetween: 5,
loop: true,
centeredSlides: true,
});
</script>
I hope someone can help me, since I could not find any information relating this topic.
Swiper is a powerful and modular javascript library to implement responsive, accessible, flexible, touch-enabled carouses/sliders on your mobile websites and apps. Can be used as a jQuery plugin.
VhJDi_mqpHw In this page we can use > mySwiper. activeIndex Index number of currently active slide Note, that in loop mode active index value will be always shifted on a number of looped/duplicated slides to get the index of current slide.
Combining the destroy parameter with Window. matchMedia() is an effective way to manage Swiper on different screen sizes. Mobile first is optional—max-width, e.g., window. matchMedia( '(max-width:31.25em)' ), will work just as well.
Try importing Navigation
from the Swiper lib. And then Swiper.use()
import Swiper, { Navigation } from 'swiper';
Swiper.use([Navigation]);
const swiper = new Swiper(...);
I had this problem while working with Next.JS
,React
. I spent almost a day figuring out what is wrong. Until I found that I should import the library using SwiperCore
. The documentation is kinda straight forward to it.
import SwiperCore, { Navigation } from 'swiper';
SwiperCore.use([Navigation]);
So basically, there's no fancy in here, it is just the library splice its code into smaller pieces so the things that you only really need will be include to your bundled. (Though tree-shaking is already a thing now).
So I added this to my _app.tsx
, and the native function will be included to all the swiper
using a navigation.
As said in documentation
By default Swiper exports only core version without additional modules (like Navigation, Pagination, etc.). So you need to import and configure them too:
// core version + navigation, pagination modules:
import Swiper, { Navigation, Pagination } from 'swiper';
// configure Swiper to use modules
Swiper.use([Navigation, Pagination]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With