Swiper.js not scrolling to final element - javascript

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,
},
});
});

Related

I am working on a project and using swiperJS to create a slider but the breakpoints are not working, your help would be very much appreciated

I am working on a project and using swiperJS to create a slider but the breakpoints are not working, your help would be very much appreciated. Everything else is working with the exception of the breakpoints......
Here is the code...
<!-- Initialize Swiper -->
<script>
var swiper = new Swiper(".slider--container", {
slidesPerView: 3,
spaceBetween: 30,
loop: true,
centerSlide: 'true',
fade: 'true',
grabCursor: 'true',
pagination: {
el: ".swiper-pagination",
clickable: true,
dynamicBullets: true
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
breakpoints: {
0:{
slidesPerView: 1,
},
520:{
slidesPerView: 2,
},
950:{
slidesPerView: 3,
},
},
});
</script>

Swiper: fraction and bullet pagination for same container

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.

How to disable drag in swiper slider

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

how to include smooth transition to the sliding image carousel using the java-script?

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.

How to make autoplay of the Swiper slider start only after the slider enters viewport?

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

Categories

Resources