0

请如何设置 jQuery .cycle() 插件以链接<a href=""到循环幻灯片名称?例子。

<div id="slides">
<div name="slide_blue"> content of slide name slide_blue</div>
<div name="slide_red"> content of slide name slide_red</div>
</div>

我需要创建链接:

<a href=".cycle() to div name slide_blue">Blue<a>
<a href=".cycle() to div name slide_red">Red<a>

jQuery 设置示例

$("#slides").cycle({
fx: 'ScrollHorz'
});

abybody 可以帮我创建设置幻灯片周期名称的链接吗?

4

1 回答 1

1

现场演示 && 代码

像这样,根据您的需要进行修改:

<div id="slides">
<div name="slide_blue"> content of slide name slide_blue</div>
<div name="slide_red"> content of slide name slide_red</div>
<div name="slide_yellow"> content of slide name slide_yellow</div>
</div>

<div>
    <a href=".cycle() to div name slide_blue" class="slide_blue">Blue<a>
    <a href=".cycle() to div name slide_red" class="slide_red">Red<a>
    <a href=".cycle() to div name slide_yellow" class="slide_yellow">Yellow<a>
</div>

<script>
(function() {

    $("#slides").cycle({
       fx: 'scrollRight'
    });

    var cycleTo = function() {
        var className = $(this).attr('class');
        var divSelected = $('#slides div[name='+className+']');
        var slideIndex = $('#slides div').index(divSelected);
        $('#slides').cycle(slideIndex); 
        return false; 
    }

    $('div a').click(cycleTo); 

}())
</script>
于 2013-04-21T08:41:29.657 回答