2010-06-04 121 views
2

我正在創建一個簡單的3張圖片幻燈片,而且我對Jquery和Cycle很新。我有幻燈片工作,3頁面鏈接,也工作。需要修改jQuery Cycle updateActivePagerLink選項

我需要完成的唯一事情是,爲當前選定的尋呼機圖像添加「activeSlide」功能,我不能在CSS中通過簡單地使用activeSlide類...因爲我想更改活動尋呼機的圖片來源...如果它只是簡單的文本編號默認情況下,我會風格的activeSlide類。

本質上,我想在test-select-on.jpg和test-select-on.jpg之間交換test-select-off.jpg。

循環代碼:

$(function() { 
    $('#testimonial-features').cycle({ 
     speed: 800, 
      timeout: '6500', 
      pause: 'true', 
      pager: '#testimonial-switcher', 
      pagerAnchorBuilder: function(idx, slide) { 
      return '#testimonial-switcher li:eq(' + idx + ') a';  
      } 
    }); 
}); 

HTML代碼:

我怎樣才能做到這一點?我想我需要通過修改updateActivePagerLink功能,從http://www.malsup.com/jquery/cycle/pager7.html採取做在updateActivePagerLink選項的東西:

$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
    $(pager).find('li').removeClass('activeLI') 
     .filter('li:eq('+currSlideIndex+')').addClass('activeLI'); 
}; 

,但就像我說的,我仍然在學習這句法,所以任何幫助將不勝感激!

回答

0

編輯:顯然,由於我不熟悉插件,我的原始答案不起作用。但是,由於您發現了部分功能,我將在此更新答案,並提供完全可行的解決方案。除了你發現的功能之外,你所需要做的只是將它們全部更改爲「關閉」(第1行),然後將活動的更改爲「開啓」(添加的內容)。

$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
    $(pager).find('img').attr('src','images/layout/test-select-on.jpg'); 
    $(pager).find('li').removeClass('activeLI') 
      .filter('li:eq('+currSlideIndex+')').addClass('activeLI') 
      .find('img').attr('src','images/layout/test-select-on.jpg'); 
}; 

讓我知道這是否有效。


原始錯誤的答案(把它留在這樣的意見意義)
看起來你可以更換 img內取其 liafter回調函數內的類 .activeLIsrc(雖然我的天堂之前沒有使用Cycle插件,只是 gleaning that last bit from the docs)。

如此循環代碼更改爲:

$(function() { 
    $('#testimonial-features').cycle({ 
     speed: 800, 
     timeout: '6500', 
     pause: 'true', 
     pager: '#testimonial-switcher', 
     pagerAnchorBuilder: function(idx, slide) { 
     return '#testimonial-switcher li:eq(' + idx + ') a';  
     }, 
     after: function(curr, next, opts) { 
     $(curr).find('img').attr('src','images/layout/test-select-on.jpg'); 
     } 
    }); 
}); 

讓我知道是否可行! (注意:如果這不起作用,請嘗試從curr中解壓$(),after: function() ......就像我說過的,之前沒有使用過這個插件)

+0

感謝您的回覆......我試了一下代碼,然後它似乎沒有做任何事情。我將$(curr)改爲curr,並將其打破,導致它不能循環。 – 2010-06-07 13:15:04

+0

沒關係,這是愚蠢簡單:\t $ .fn.cycle.updateActivePagerLink =函數(尋呼機,currSlideIndex){ $(尋呼機).find( '禮')removeClass( 'activeItem')addClass('inactiveItem。 ').filter(' 禮:當量( '+ currSlideIndex +') ')removeClass(' inactiveItem ')addClass(' activeItem'); ('.mrc','images'/ layout/test-select-off.jpg'); \t $('。activeItem ')發現(' IMG ')ATTR(' SRC」, '圖像/佈局/測試選-on.jpg'); \t}; – 2010-06-07 13:51:44

+0

@ Andrew-Parisi我用一個應該可以工作的解決方案編輯我的答案。讓我知道。編輯:哎呀,你打敗了我。 – mVChr 2010-06-07 13:56:29