Trigger ResponsiveSlides.js programmatically

时光毁灭记忆、已成空白 提交于 2019-12-08 00:08:55

问题


I'm using ResponsiveSlides.js and I am trying to change slides programmatically. I've tried it two ways, and neither have worked.

  1. Calling the plugin's slideTo function from a click event on the thumbnail, passing the index of the slide it should go to.

  2. Use .trigger("click") on the <li> corresponding to the index of the slide it should go to, ex:

    $(".rslides_tabs li").eq($theIndex).trigger("click");


回答1:


You can't call the slideTo() function because it is assigned only to a local variable in the plugin method.

Your second attempt was close, but it looks like the click handler is bound to an <a> element.

Try:

$('.rslides_tabs').find('a').eq(index).trigger('click');

Where index is the zero-based index of the slide you want to show.

Note: If you passed a value in for the "namespace" option, then you would have to change the class name from "rslides_tabs" to whatever value you passed + "_tabs". So if you passed ( namespace: 'mynamespace' } for the options, the class would be "mynamespace_tabs".



来源:https://stackoverflow.com/questions/15594790/trigger-responsiveslides-js-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!