Jquery滑块因未知原因无法工作

时间:2013-01-01 04:59:13

标签: jquery slider

我正在尝试使用之前已经使用过很多次的jquery滑块 - 但这次它不起作用,我无法弄清楚原因。

这是HTML代码,基本上只是一个主滑块div,里面有另一个div用于幻灯片,每个幻灯片div都有一类幻灯片(抱歉絮絮叨叨,我不能发布这个没有'更多解释'):< / p>

<div id="slider">
<div id="slides">
    <div class="slide">
        <img src="images/portfolio/web1.jpg" alt=""/>
    </div>
    <div class="slide">
        <img src="images/portfolio/web5.jpg" alt=""/>
    </div>
</div>
    <img src="images/arrow-L.png" alt="Left" id="slider-arrow-left"/>
    <img src="images/arrow-R.png" alt="Right" id="slider-arrow-right"/>
</div>

CSS,只需设置高度和宽度:

#slider{height: 200px; position: relative; z-index: 1;}
#slider #slides {height: 200px; width: 883px; overflow: hidden; position: absolute; top: 0px; left: 0px;}
#slider #slides .slide{height: 200px; width: 883px;}
#slider img#slider-arrow-left {position: absolute; left: -30px; top: 80px; cursor: pointer;   z-index: 999;}
#slider img#slider-arrow-right{position: absolute; right: 0px; top: 80px; cursor: pointer; z-index: 999;}

和Jquery:

$(document).ready(function(){


    $('#slides').cycle({ 
        fx:      'scrollHorz', 
        speed:  'slow', 
        timeout: 10000, 
        pause:   1,
        prev: $('#slider-arrow-left'),
        next: $('#slider-arrow-right'),
        cssBefore:{ 
            top: 0,
            opacity: 1,
            display: 'block'
        }, 
        animOut: {  
            top: 360
        },
        before: function(curr, next, opts){
            var $curr = $(curr);
            var $next = $(next);
        },
        pause: 1,
        pager: '#slider-controls',
        pagerAnchorBuilder: function (idx, slide) {
            return '#slider-controls li:eq(' + idx + ') a';
        }
    });
});

1 个答案:

答案 0 :(得分:2)

我使用jQuery cycle plugin尝试了您的示例。看起来很好,

$(document).ready(function(){

    $('#slides').cycle({ 
        fx:      'scrollHorz', 
        speed:  'slow', 
        timeout: 0, //prevents auto start of jquery cycle.
        pause:   1,
        prev: $('#slider-arrow-left'),
        next: $('#slider-arrow-right'),
        cssBefore:{ 
            top: 0,
            opacity: 1,
            display: 'block'
        }, 
        animOut: {  
            top: 360
        },
        before: function(curr, next, opts){
            var $curr = $(curr);
            var $next = $(next);
        },
        pause: 1,
        pager: '#slider-controls',
        pagerAnchorBuilder: function (idx, slide) {
            return '#slider-controls li:eq(' + idx + ') a';
        }
    });

});​

这里:

jsFiddle

你可以相应调整它。