I am using the jQuery slider called Swiper in my project.
/
I am new to programming (js / jquery). I want to execute a function, some jquery code to be more specific, whenever the first slide of the slider is active. I think their API makes this possible, but I have no idea how to use. If somebody could help, I'd appreciate. Here's their API:
.php
Thanks.
I am using the jQuery slider called Swiper in my project.
http://www.idangero.us/sliders/swiper/
I am new to programming (js / jquery). I want to execute a function, some jquery code to be more specific, whenever the first slide of the slider is active. I think their API makes this possible, but I have no idea how to use. If somebody could help, I'd appreciate. Here's their API:
http://www.idangero.us/sliders/swiper/api.php
Thanks.
Share Improve this question asked Sep 10, 2013 at 15:04 Amar SylaAmar Syla 3,6533 gold badges32 silver badges71 bronze badges3 Answers
Reset to default 13I build a little demo in jsfiddle to demonstrate how to react on slide events with "swiper":
http://jsfiddle.net/KhgFX/2/
Use the Event-Callback functions by swiper, as mentioned in the API-docu.
$(document).ready(function () {
$(function () {
var mySwiper = $('.swiper-container').swiper({
mode: 'horizontal',
watchActiveIndex: true,
loop: true,
onSlideChangeStart: function (swiper) {
console.log('slide change start - before');
console.log(swiper);
console.log(swiper.activeIndex);
//before Event use it for your purpose
},
onSlideChangeEnd: function (swiper) {
console.log('slide change end - after');
console.log(swiper);
console.log(swiper.activeIndex);
//after Event use it for your purpose
if (swiper.activeIndex == 1) {
//First Slide is active
console.log('First slide active')
}
}
});
})
});
Doesn't seem that the other jsfiddle example works anymore. For others who want to get the right libraries set up to see this working, see:
http://jsfiddle.net/kp8a8ugd/1/
var swiper = new Swiper('.swiper-container'); //just a simple setup
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'vertical',
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
});