如何滑动到滑块上的特定幻灯片

Gop*_*pal 1 html jquery

我想使用网址将滑块滑动到特定的幻灯片.我可以使用幻灯片编号滑动到特定幻灯片,但我需要使用其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');
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

Pre*_*ari 5

你可以找到幻灯片的索引,其id为'sunset'..

如果你的flexslider HTML结构是这样的..

<div id="slider">
     <div>...<img/>...</div>
     <div>...<img/>...</div>
     <div id="sunset">...<img/>...</div>
     <div>...<img/>...</div>
</div>
Run Code Online (Sandbox Code Playgroud)

试试这个代码..

var index = $('#sunset').index();   // will give you 2
$('#slider').flexslider(index);   // will take you to that slide
Run Code Online (Sandbox Code Playgroud)