I have set up a Swiper slider that currently has an arrow navigation and a bullet pagination at the top.
var swiper = new Swiper('.swiper-container', {
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
slidesPerView: 'auto',
spaceBetween: 30,
speed: 300,
effect: 'fade',
fadeEffect: {
crossFade: true
},
loop: true,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
I need to add another pagination at the bottom, this time a type fraction (1 / 11, 2 / 11).
pagination: {
el: '.swiper-pagination',
type: 'fraction',
}
I've tried following the answer given here, but that displays Slide 1, Slide 2, Slide 3 all the times instead of only in the relative slides.
See here the JSFiddle of my current slider.
Related
I tried to add swiper.js to tab elements in Oxygen Builder but it is not scrolling to the end unless I set swiper.js to 'centeredslides:true' or 'loop:true' but loop breaks Oxygen Builder tabs.
Any ideas on how to fix this? Can provide video of error if needed..
jQuery(document).ready(function() {
const swiper = new Swiper('.swiper', {
// Optional parameters
freeMode: true,
slidesPerView: 8,
centeredSlides: true,
spaceBetween: 0,
direction: 'horizontal',
loop: false,
freeMode: true,
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
scrollbar: {
el: ".swiper-scrollbar",
hide: false,
},
});
});
I have an .image-slider__fraction block that I tried to set up to display the number of the active slide from the total number of slides, but for some reason in the javascript it gives me the error "Uncaught ReferenceError: myImageSLider is not defined", but I don't understand why
Site http://ilyin1ib.beget.tech/
Code https://jsfiddle.net/qav8z7f3/
let mySliderAllSlides = document.querySelector('.image-slider__total');
let mySliderCurrentSlide = document.querySelector('.image-slider__current');
mySliderAllSlides.innerHTML = myImageSLider.slides.length;
myImageSLider.on('slideChange', function() {
let currentSlide = ++myImageSLider.realIndex;
mySliderCurrentSlide.innerHTML = currentSlide;
});
<div class="image-slider__fraction">
<div class="image-slider__current">1</div>
<div class="image-slider__sepparator">/</div>
<div class="image-slider__total">1</div>
</div>
You can achieve it like this. https://jsfiddle.net/zoymLphf/
Use swiper API methods. Counting the total number of slides is kinda tricky when you use loop mode, maybe there is a more elegant solution for this.
const swiper = new Swiper('.image-slider', {
// Optional parameters
slidesPerView: 3,
on: {
init: function(sw) {
$('.image-slider__total').text($('.swiper-slide:not(.swiper-slide-duplicate)').length)
$('.image-slider__current').text(sw.realIndex + 1)
},
slideChange: function (sw) {
$('.image-slider__current').text(sw.realIndex + 1)
},
},
spaceBetween: 30,
direction: 'horizontal',
centeredSlides: true,
loop: true,
loopedSLides: 3,
simulateTouch: true,
grabCursor: true,
speed: 800,
pagination: {
el: '.swiper-pagination',
type: 'progressbar'
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
autoplay: {
delay: 1000,
}
});
I am using swiper slider version 3.3.1.
I did apply this code, but not working
var swiper = new Swiper('.swiper', {
speed: 400,
autoHeight: false,
loop: true,
autoplay: 2500,
autoplayStopOnLast: false,
pagination: '.swiper-pagination',
paginationType: "bullets",
simulateTouch:false,
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
effect: 'fade',
slidesPerView: 1,
scrollbar: {
container: '.swiper-scrollbar',
draggable: false,
}
});
I think it should be
allowTouchMove: false
To add onto Veronica's answer, you can set allowTouchMove: false as a parameter for the Swiper.
Example in React:
<Swiper
allowTouchMove={false} // disable touch / drag swiping
{...swiperProps}
>
{...slides}
</Swiper>
You can read more in the Swiper Documentation
I have made an automatic sliding image carousel in my website with the the HTML, CSS & Java-Script but the transition from one image to another is not good. Please guide me what to add in the Java-Script area to make the transition smooth?
I have tried the below java-script but I also want to add the smooth transition between the images.
<script>
var swiper = new Swiper('.swiper-container', {
slidesPerView: 3,
spaceBetween: 30,
autoplay: {
delay: 3000,
disableOnInteraction: false,
},
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
</script>
Add a by default fade effect:
var swiper = new Swiper('.swiper-container', {
slidesPerView: 3,
spaceBetween: 30,
autoplay: {
delay: 3000,
disableOnInteraction: false,
},
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
effect: fade,
fadeEffect: {
crossFade: true }
});
More effects and animations for your carousel are provided here.
I'm using this code to initialize swiper slider.
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
pagination: '.swiper-pagination',
paginationClickable: true,
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
spaceBetween: 0,
parallax: true,
autoplay: 5000,
speed: 800,
autoplayDisableOnInteraction: false
})
Since the slider is positioned inside the fourth section of the page and is visible only after the page is scrolled down, I would like to make the autoplay start only after the slider enters the viewport.
Is there a way to do this?
var mySwiper = new Swiper('.swiper-container', {
autoplay: {
delay: 5000,
},
});
Assuming you're trying play on 4th slides:
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
pagination: '.swiper-pagination',
paginationClickable: true,
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
spaceBetween: 0,
parallax: true,
autoplay: 5000,
speed: 800,
autoplayDisableOnInteraction: false,
onSlideChangeStart: function(s){
if (s.activeIndex === 3) {
// do something here, 4th slide is active now and so on
console.log('hi! Try to reach 4th slides');
s.startAutoplay(); // calling autoplay on 4th slides.
}
}
})
You could potentially use something like jquery appear - https://github.com/morr/jquery.appear
$('mySwiperContainer').on('appear', function(event, $all_appeared_elements) {
// this element is now inside browser viewport
var mySwiper = new Swiper ('.swiper-container', {
// Optional parameters
pagination: '.swiper-pagination',
paginationClickable: true,
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
spaceBetween: 0,
parallax: true,
autoplay: 5000,
speed: 800,
autoplayDisableOnInteraction: false
})
});
Object with autoplay parameters needs to be used, or just boolean true to enable with default settings to enable autoplay. Here is an example with delay (between transitions in ms) parameter:
const swiper = new Swiper('.swiper', {
autoplay: {
delay: 5000,
},
});
Documentation reference here