How to disable drag in swiper slider - javascript

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

Related

Swiper.js not scrolling to final element

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

Incorrect slides amount and slides overlay Swiper JS

guys!
I'm using Swiper slide JS, bu at first I created Joomla module with this script. And my slider works incorrect.
At first, I can't understand why if I display slidePerView: 4 - on my website displaying each slide with width 100%. It's strange.
All slides overlay each other. You can to see this on my screenshot:
Screenshot
This is link to my website: https://hmc.bold.com.sa/services/dental-services
It's more simple to look on website.
This is JS code:
<script> let swiper146 = new Swiper(".swiper-doctors", {
navigation: {
nextEl: '.swiper-button-next146',
prevEl: '.swiper-button-prev146',
},
spaceBetween: 20,
slidesPerView: 4,
effect: "fade",
hashNavigation: false,
history: false,
lazy: false,
autoHeight: false,
zoom: false,
rewind: false,
grabCursor: false,
loop: true,
loopPreventsSlide: true,
breakpoints: {1920: { slidesPerView: 4, spaceBetween: 20},} });</script>
Help me please to fix this issue. Thanks

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 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