2011-02-07 40 views
0

后来,我为需要编号活动状态的客户端实现了jCarousel图像解决方案。经过一番搜索后找到了答案,但注意到首选的循环选项不起作用。jCarousel - 实现活动状态并包装:循环

会发生什么情况是,一旦旋转木马已经遍历所有(5)图像,在返回到第一个图像时,活动状态将会丢失,因为根据jcarousel它实际上是第6个不断增加)。

我只是继续前进,而是用wrap:'both',它至少有一个正常工作的活动状态。但是现在客户说他们不喜欢这种效果,只想让动画在最终图像后返回到位置1。这意味着我需要得到'wrap':'都'以某种方式工作。

下面是我目前的代码。有人可以解决这个问题,因为它有点高于我的头!

function highlight(carousel, obejctli,liindex,listate){ 
    jQuery('.jcarousel-control a:nth-child('+ liindex +')').attr("class","active"); 
}; 

function removehighlight(carousel, obejctli,liindex,listate){ 
    jQuery('.jcarousel-control a:nth-child('+ liindex +')').removeAttr("class","active"); 
}; 



    jQuery('#mycarousel').jcarousel({ 
     initCallback: mycarousel_initCallback, 
     auto: 5, 
     wrap: 'both', 
     vertical: true, 
     scroll: 1, 
     buttonNextHTML: null, 
     buttonPrevHTML: null, 
     animation: 1000, 
     itemVisibleInCallback: highlight, 
     itemVisibleOutCallback: removehighlight 

    }); 
}); 

在此先感谢

回答

0

我会把一些元数据到李中的一个元素的属性,例如:

<ul class="carousel"> 
    <li><img src="whatever.png" rel="1" /></li> 
    <li><img src="whatever.png" rel="2" /></li> 
    <li><img src="whatever.png" rel="3" /></li> 
</ul> 

然后做

function highlight(carousel, obejctli,liindex,listate){ 
    var nthchild = $("img", obejctli).attr('rel'); //not sure if this is the syntax 
    jQuery('.jcarousel-control a:nth-child('+ nthchild +')').attr("class","active"); 
}; 

如果我记得没错,objectli不是一个jquery对象,它是一个dom元素。您可能必须调整代码,因为我不记得如何在非jQuery元素中使用选择器。

+0

感谢Duopixel。我把这一个交给了一位同事,她提出了和你一样的答案。 干杯。 – swisstony 2011-02-13 08:13:35