javascriptjquerycallbackswiper.js

How to use a callback


I'm looking to use a callback on this script - the third callback onSlideChangeStart(swiper) http://idangero.us/swiper/api/#.V9CMp5grJlY but I've never used a callback and am at a loss where to start.

So basically I want to add/remove a class to an element elsewhere on the page where the other element as a class equal to a datatag on the swiper slide. Any tips on how to start this?

my current working js is:

//swiper script for featured director spots
//initialize swiper when document ready
var mySwiper = new Swiper ('.swiper-container', {
    // Optional parameters
    direction: 'horizontal',
    loop: true,

    keyboardControl: true,
    mousewheelControl: true,

    pagination: '.swiper-pagination',
    /*paginationElement: 'span',*/
    paginationClickable: true,



    paginationBulletRender: function (index, className) {
  return '<a class=" ' + className + ' "><i class="fa fa-dot-circle-o active"></i><i class="fa fa-circle non-active"></i></a>';
    }

})

I know how to add/remove/toggle a class but not sure how to get it to fire using the callback. Please advise.

So basically I need to know how to add the callback - maybe inside the callback have a bit add more code here or similar.

Thank you.


Solution

  • Should be something like:

        mySwiper.on('onSlideChangeStart', function () {
           // do your stuff here
        });
        // do a console log on mySwiper to see what exactly is being passed
        console.log(mySwiper);