2013-03-23 47 views
1

是否有可能在flexslider中显示特定图像,当从另一个主页链接被点击(如锚“www.mysite.html#slider3”)?我有一个带有textlinks的页面。如果用户点击像“去滑块3”这样的链接,带有弹性滑块的网站就会出现并显示滑块3.jquery flexslider链接到特定图像

请有人可以帮助我吗?我已经阅读过这个帖子(jQuery FlexSlider - Link to specific image),但这对我不起作用,我不知道为什么。

感谢与约我的英语不好对不起, CEDE

回答

2

Flexslider提供了一个名为“startAt”,其接受表示滑动第一以显示索引属性。您也可以通过将'slideshow'参数设置为false来禁用自动播放幻灯片。如果您在创建幻灯片之前抓取要开始的幻灯片参考,则可以使用这些参数。

// create a variable to store the slide index to start at. 
startAtSlideIndex = 0; 

// see if a tab anchor has been included in the url 
if (window.location.hash != '') { 

    // Set the startAtSlideIndex variable to one less than the ordinal passed 
    // note: if you have more than 9 slides, this will fall down and you'll 
    //  have to do some more complex string manipulation. 
    //  A querystring variable might be easier, especially if you use 
    //  someone else's url parser ;) 
    // Important: assumes the format of the hash is '#tabN' where N is the digit we want. 
    startAtSlideIndex = window.location.hash.substr(4,1)-1; 
} 

$("#flexslider-container").flexslider({ 

    // other flexslider params 

    // set the flexslider startAt param to the value of the startAtSlideIndex variable 
    startAt: startAtSlideIndex 

}); 

编辑:我忘记了位置对象有一个'哈希'属性在我原来的答案。

+0

嗨Michael, 感谢您的回答!我很抱歉这么晚回答。由于这不是我的主要工作,我甚至无法测试它。现在我会弥补并再次报告我。我有一个关于你的代码的问题:什么意思是“(4,1)”? 不幸的是,我有超过9张幻灯片...我有什么要更改代码? 非常感谢! – CeDe 2013-06-16 13:21:33

+0

哇!它很棒!再次感谢你!我只用了几张图片就尝试过了,但现在我想让它使用超过9张图片。请你能告诉我我必须做什么吗? – CeDe 2013-06-16 18:25:04

1

这又是我:-)看来,它适用于超过9张幻灯片太:我只是改变一下代码:

// Important: assumes the format of the hash is '#tabNN' where NN is the digit we want. startAtSlideIndex = window.location.hash.substr(4,2)-0;

感谢和问候!