javascript - 如何使用回调

标签 javascript jquery callback swiper.js

我希望在此脚本上使用回调 - 第三个回调 onSlideChangeStart(swiper) http://idangero.us/swiper/api/#.V9CMp5grJlY但我从未使用过回调,并且不知道从哪里开始。

所以基本上我想向页面上其他位置的元素添加/删除一个类,其中另一个元素作为类等于滑动器幻灯片上的数据标签。关于如何开始这个有什么建议吗?

我当前的工作js是:

//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>';
    }

})

我知道如何添加/删除/切换一个类,但不知道如何使用回调来触发它。请指教。

所以基本上我需要知道如何添加回调 - 也许回调内部有一些在此处添加更多代码或类似的内容。

谢谢。

最佳答案

应该是这样的:

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

关于javascript - 如何使用回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39379782/

相关文章:

javascript - 如何使用 javascript 在 HTML 中的数组中显示访问的(通过 for 循环)对象

javascript - Javascript 如何维护单个全局命名空间

jquery - 如何在 MVC 4 中加载 View 而不重新加载布局?

javascript - 灯箱无法正常工作

c++ - 来自类方法的回调 (C++)

javascript - 如何避免异步编程中的回调链?

javascript - 在 JS 中使用 indexOf() - 否定空值是否明智以及如何操作?

javascript - 使用 jquery 从一列拖放到另一列

javascript - 如何等待一个 jquery 动画在下一个动画开始之前完成?

javascript - 使用 Javascript 根据现有值更改属性值