我想使用网址将滑块滑动到特定的幻灯片。我可以使用幻灯片编号滑动到特定幻灯片,但我需要使用其ID滑动到它。
例如:如果我打开slider.html?pic=sunset
,它会将滑块滑动到幻灯片id=slide
$(window).load(function () {
$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: true,
itemWidth: 210,
itemMargin: 5,
asNavFor: '#slider'
});
$('#slider').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: true,
sync: "#carousel",
start: function (slider) {
$('body').removeClass('loading');
}
});
});
答案 0 :(得分:5)
你可以找到幻灯片的索引,其id为'sunset'..
如果您的flexslider HTML结构类似..
<div id="slider">
<div>...<img/>...</div>
<div>...<img/>...</div>
<div id="sunset">...<img/>...</div>
<div>...<img/>...</div>
</div>
试试这段代码..
var index = $('#sunset').index(); // will give you 2
$('#slider').flexslider(index); // will take you to that slide
答案 1 :(得分:3)
您可以访问滑块对象,如:
var exampleSlider = $('#slider').data('flexslider');
// now you can access all the methods for example flexAnimate
exampleSlider.flexAnimate(..);
然后用索引滑动。你需要:
exampleSlider.flexslider(3);//3 is index here