当新幻灯片进入视图时移动我的滑块缩略图

时间:2011-02-10 12:00:50

标签: javascript jquery slider cycle jquery-cycle

脚本:jQuery Cycle滑块:http://jquery.malsup.com/cycle/

我正在使用以下代码将滑块缩略图容器向左移动“130px”,就在下一张幻灯片进入视图之前。然后在到达最后一张幻灯片时将边距重置为“0px”。这很好用,但容器在第三张幻灯片之前不会移动。

这是我正在使用的代码:

function onBefore(currElement, nextElement, opts, isFoward) {
    var currentslide = opts.currSlide + 1; 
    if(currentslide == opts.slideCount) {
        jQuery(".slider-nav").animate({marginLeft: '0'});
    } else if(currentslide > 1 && currentslide != opts.slideCount) {
        jQuery(".slider-nav").animate({marginLeft: '-=133'});
    }           
}

一旦第二张幻灯片进入视图,我怎样才能让它移动。注意:使用“> 0”替换上面代码中的“> 1”会在页面加载后立即移动容器。

1 个答案:

答案 0 :(得分:0)

我不确定调用此函数的上下文。但我想你想要以下代码:

function onBefore(currElement, nextElement, opts, isFoward) {
      if(opts.currSlide == opts.slideCount) {
         jQuery(".slider-nav").animate({marginLeft: '0'});
     } else { 
         jQuery(".slider-nav").animate({marginLeft: '-=133'});
     }
}

如果这不起作用,可能是因为您的第一张幻灯片是(slideCount = 0)而不是(slideCount = 1)。如果是这样,将IF测试更改为:

      if(opts.currSlide == (opts.slideCount - 1)) {

此致        尼尔

相关问题