jQuery 检测光滑滑块何时初始化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28236840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:26:18  来源:igfitidea点击:

Detect when slick slider initialises

jqueryslick.js

提问by user1937021

I'm trying to fire some code when slickinitializes. Apparently in the newest version 1.4 "callback methods have been deprecated and replaced with events."

我试图在slick初始化时触发一些代码。显然在最新的 1.4 版中“回调方法已被弃用并被事件替换”。

This doesn't work for me though:

但这对我不起作用:

$('.spv-slider').on('init', function(event, slick){
    console.log("initialised")
});

what's wrong with it?

它出什么问题了?

回答by der-lukas

I'm not sure at which point you tried to initialize slickslider, but you have to do it afterbinding the initevent.

我不确定您在哪一点尝试初始化 slickslider,但您必须绑定init事件执行此操作。

So write your piece of code as you did and after that initialize the slider:

因此,按照您的方式编写代码,然后初始化滑块:

$('.spv-slider').on('init', function(event, slick){
    console.log("initialized")
});

And then:

进而:

$('.spv-slider').slick();