1

有没有人可以共享 mypage.com/#slide1 或 mypage.com/#slide2 之类的链接并调用我的滑块的特定幻灯片?

谢谢。

4

1 回答 1

1

我想我有一个想法:

首先,您需要创建一个带有导航控件的 flexslider

然后,使用名为 slide1、slide2、slideX 的井号标签,您知道要使用 (X-1) 元素,所以这里有一个示例:

(jQuery.noConflict())(function($) {
    //Get your hash tag
    var loc = $(location).attr('href');
    var idx = 1;
    if(loc.lastIndexOf('#') != -1)
    {
        idx = loc.substr(loc.lastIndexOf('#')+1).replace('slide', '');
    }

    //verify that idx is really a number
    if(isNaN(idx-0))
    {
        idx = 1;
    }

    //Click on your nav (idx starts at 0)
    $('.flex-control-nav li:eq('+(idx-1)+') a').trigger('click');
    });

另一种方法是像这样使用 startAt 参数:

(jQuery.noConflict())(function($) {
    //Get your hash tag
    var loc = $(location).attr('href');
    var idx = 1;
    if(loc.lastIndexOf('#') != -1)
    {
        idx = loc.substr(loc.lastIndexOf('#')+1).replace('slide', '');
    }

    //verify that idx is really a number
    if(isNaN(idx-0))
    {
        idx = 1;
    }

    $('#yourFlexSlider').flexslider ({
        startAt: idx
    });
});
于 2012-08-09T19:39:35.620 回答