2011-02-07 38 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