简体   繁体   English

更改功能内部的滑动滑块功能不起作用

[英]Slick slider function inside change function doesn't work

I have built a product page that has a colour variation select. 我建立了一个具有颜色变化选择的产品页面。 I'm trying to make it work that when a user selects a colour from the dropdown the slick slider will go to the corresponding slide. 我试图使其工作,当用户从下拉列表中选择一种颜色时,光滑的滑块将转到相应的滑块。

I have added data-attr to each slick slide that contain the colour name and use this to the slide index. 我已经向每个包含颜色名称的光滑幻灯片添加了data-attr,并将其用于幻灯片索引。

The slickgoto function works when I move it outside of the change function. 当我将它移到change函数之外时,slickgoto函数会起作用。

  $( "#pa_colour" ).change( function() { var prod_color = $( "#pa_colour option:selected" ).val(); var slide_index = parseInt( $( ".slider-for" ).find('[data-color="' + prod_color + '"]').data("slick-index") ) -1; $( ".slider-for" ).slick( 'slickGoTo', slide_index, false); }); 

Thanks 谢谢

No sure the false is necessary. 不确定false是否必要。 Have you tried: 你有没有尝试过:

$('.slide-for').slick('slickGoTo', slide_index);

Otherwise I would adjust it to: 否则,我会将其调整为:

var slideshow = $( ".slider-for" );

slideshow.slick({ ... });

$( "#pa_colour" ).change( function() { 

   var prod_color = $( "#pa_colour option:selected" ).val();
   var slide_index = parseInt( $( ".slider-for" ).find('[data-color="' + prod_color + '"]').data("slick-index") ) -1;

   slideshow.slick( 'slickGoTo', slide_index );

});

Hope this helps. 希望这可以帮助。

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

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