2012-06-14 45 views
1

這幾乎是我想要完成的。讓每個圖像都以不同的過渡效果出現。jQuery-Cycle:如何更改每個新圖像的過渡效果

你能幫我解決並找出我的代碼有什麼問題嗎?

的jQuery:

var url = 'http://www.mywebsite.com/'; 
var img_dir = '_img/slideshow/'; 
var fx = 
    [ 
    'blindX', 
    'blindY', 
    'blindZ', 
    'cover', 
    'curtainX', 
    'curtainY', 
    'fade', 
    'fadeZoom', 
    'growX', 
    'growY', 
    'scrollUp', 
    'scrollDown', 
    'scrollLeft', 
    'scrollRight', 
    'scrollHorz', 
    'scrollVert', 
    'shuffle', 
    'slideX', 
    'slideY', 
    'toss', 
    'turnUp', 
    'turnDown', 
    'turnLeft', 
    'turnRight', 
    'uncover', 
    'wipe', 
    'zoom' 
    ]; 
var index = 0; 

$(function() { 
    var $slideshow = $('#slideshow'); 
    // add slides to slideshow (images 2-3) 
    for (var i = 2; i < 13; i++) 
     $slideshow.append(
      '<a href="' + url + img_dir + i+'.jpg" title="Slideshow">'+ 
       //src="http://www.mywebsite.com/_img/slideshow/" 
      '<img src="' + url + img_dir + i+'.jpg" width="100" height="100" />'+ 
      '</a>'); 
    // start the slideshow 
    $slideshow.cycle(
    { 
     if(index < fx.length) { index++; } 
     else { index = 0; } 
     fx:  fx[index], 
     timeout: 3000 
    }); 
}); 
+0

我是很新的jQuery和一般的編程,但我想你應該添加一個不同的「計數器「var在你的循環中,然後用它在你的fx數組中設置效果。 – rafaelbiten

回答

4

要使用所有的效果那是相當容易:

http://jsfiddle.net/lucuma/tcRCj/14/

$('#slideshow').cycle({fx:'all'});​ 

此外,如果你只是想指定某幾個:

$('#slideshow').cycle({fx:'scrollDown,scrollLeft,fade'}); 

如果你不想隨機效果的順序(默認情況下將隨機):

$('#slideshow').cycle({fx:'scrollDown,scrollLeft,fade', randomizeEffects:0}); 
+0

@lucma是否可以選擇初始效果? Ej,幻燈片放映以「淡入淡出」開始並循環播放(永遠)? – Omar

+0

是的,請確保您將每個循環元素設置爲'display:none',然後調用jquery的fadein並在回調中使用您的選項啓動循環(http://jquery.malsup.com/cycle/fade-in-first。 ); $('#slideshow img:first')。fadeIn(1000,function(){$('#slideshow')。cycle(); }); – lucuma