简体   繁体   English

如何完美模拟slick.js中的上一个/下一个按钮?

[英]How can I perfectly emulate the prev/next buttons in slick.js?

For reference, I'm talking about Ken Wheeler's Slick slider . 作为参考,我正在谈论Ken Wheeler的Slick滑块

Having some problems getting "dynamic" (loaded from a database) images showing up when my page is loaded, only the top 20px or so is showing but not the rest for some reason. 加载页面时出现一些“动态”(从数据库加载)图像显示的问题,由于某种原因,仅显示顶部的20px左右,而其余的则不显示。 If you drag them or click the prev/next buttons they will show fully and the slider works as it should. 如果拖动它们或单击上一个/下一个按钮,它们将完全显示 ,并且滑块将按预期工作。

My work-around, thus, is to display a short text saying "Click to show images" that is hidden behind the images if they do show up, but displayed if things are buggy. 因此,我的解决方法是显示一条短文字,即“单击以显示图像”,如果确实显示,则隐藏在图像后面,但如果出现问题,则显示该文本。

Since the prev/next buttons are working even when the bug comes up, I figured I'd do this in my click event for the div-to-fix-bug : 由于即使出现错误,上一个/下一个按钮也可以正常工作,因此我想在div-to-fix-bug click事件中这样做:

$('.gallery').slick('slickNext')
//gallery is the slider

But it won't work, which leads me to believe that the actual prev/next buttons do something else! 但这是行不通的,这使我相信实际的上一个/下一个按钮会做其他事情! I'm too much of a novice to go through the source code so I'm asking here instead how I can emulate the prev/next buttons better than slickNext . 我对新手来说太过slickNext因此我在这里问的是,相比slickNext我如何更好地模仿prev / next按钮。

Instead of referring to the slickNext, it's better to act before slides change: 与其引用slickNext,不如在更改幻灯片之前采取行动:

$('.your-element').on('beforeChange', function(event, slick, currentSlide, nextSlide){
  // add your bug-fixing script here and do so only for the relevant slide (nextSlide)
});

Wasn't sure what your exact question was, if it wasn't helpful please add a JSFiddle. 不确定您的确切问题是什么,如果没有帮助,请添加JSFiddle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM