2011-06-16 63 views
2

在我的嵌套幻燈片中,我有'prev'和'next'控件。如果你在第一張幻燈片上,我希望能夠減少'prev'的css不透明度,如果你在最後一張幻燈片上,我希望能夠減小'next'的css不透明度。jquery循環插件,嵌套幻燈片,'後'選項或測試第一個和最後一個圖像

'after:onAfter'選項應該足夠了,但是當放置在我的嵌套幻燈片控件的代碼中時,它看起來不起作用。

是否有一種方法可以在嵌套幻燈片中正確實現'after',或者可以測試嵌套幻燈片中的第一張和最後一張圖片? Thankyou

這是我的代碼。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() {      
// init and stop the inner slideshows 
var inners = $('.inner-slideshow').cycle().cycle('stop'); 
var slideshow = $('#slideshow').cycle({ 
    fx:  'fade', 
    speed: 'fast', 
    timeout: 0, 
    pager: '#nav', 
    pagerAnchorBuilder: function(idx, slide) { 
     // return sel string for existing anchor 
     return '#nav li:eq(' + (idx) + ') a'; 
    }, 
    before: function() { 
     // stop all inner slideshows 
     inners.cycle('stop'); 
     // start the new slide's slideshow 
     $(this).cycle({ 
      fx: 'scrollHorz', 
      speed: 'fast', 
      timeout: 0, 
      prev: '#prev', 
      next: '#next', 
      nowrap: 1 
     }); 
    } 
}); 
}); 
</script> 
<title>dev</title> 
</head> 
<body> 
<ul id="nav"> 
<li><a href="#">Top Slidehsow 1</a></li> 
<li><a href="#">Top Slidehsow 2</a></li> 
</ul> 
<div id="controls"> 
    <a id="prev" href="#">&lt; Prev</a> 
    <a id="next" href="#">Next &gt;</a> 
</div> 
<div id="slideshow"> 
    <div class="inner-slideshow"> 
     <img src="http://cloud.github.com/downloads/malsup/cycle/beach1.jpg" width="200" height="200"> 
     <img src="http://cloud.github.com/downloads/malsup/cycle/beach2.jpg" width="200" height="200"> 
    </div> 
    <div class="inner-slideshow"> 
     <img src="http://cloud.github.com/downloads/malsup/cycle/beach4.jpg" width="200" height="200"> 
     <img src="http://cloud.github.com/downloads/malsup/cycle/beach5.jpg" width="200" height="200"> 
     <img src="http://cloud.github.com/downloads/malsup/cycle/beach6.jpg" width="200" height="200"> 
    </div> 
</div> 
</body> 
</html> 
+0

首先,該代碼甚至沒有做什麼,我想你想要的。玩過各種選項後(看http://jsfiddle.net/morrison/m8AFG/1/到http://jsfiddle.net/morrison/m8AFG/4/),我無法讓你的代碼有兩個幻燈片,在它們之間切換。 – 2011-06-16 17:27:23

+0

嗨,對不起,我看看你的鏈接。我已經將我的問題中的代碼從代碼片段更新到應該工作的整個頁面。 – 2011-06-16 18:15:10

回答

0

這將有助於瞭解什麼插件,您正在使用,但大多數滑塊插件有一個參數,你可以添加一個功能,那都會被調用時的實際滑動情況發生,像「的onChange」 。如果這個插件有這樣的功能,你可以使用一些簡單的Javascript來直接操作CSS或者元素,或者向它們添加一個類,以允許你在CSS中操縱它們。

所以,你需要知道當前索引 - 看起來像「IDX」可以提供這一點,那麼你會做類似的信息(僞代碼)

if(currentSlideNumber == slides.length){ 
    //Reduce opacity of next tab 
}else if(currentSlideNumber == 1){ 
    //Reduce opacity of previous tab 
} 

其中「currentSlideNumber」是當前指數,和slides.length計數幻燈片的數量 - 在Javascript中,這將是:

$('.inner-slideshow').children('img').length 
+0

他正在使用循環插件:http://jquery.malsup.com/cycle/ – 2011-06-16 17:13:59

+0

因此,看看選項頁面後的選項'後:'看起來像它可以讓你添加上面的代碼到你的頁面,有意義嗎? – 2011-06-16 17:17:31

+0

嗨,湯姆,謝謝你是有道理的。我應該更仔細地看看'後'選項。我沒有注意到,而不是傳遞預定義的值,你也可以爲它寫函數。 – 2011-06-16 18:23:01

2

我想這是你想要的東西(編輯你的例子): http://jsfiddle.net/m8AFG/18/

$(document).ready(function() { 
    // init and stop the inner slideshows 
    var inners = $('.inner-slideshow').cycle().cycle('stop'); 
    var slideshow = $('#slideshow').cycle({ 
     fx: 'fade', 
     speed: 'fast', 
     timeout: 0, 
     pager: '#nav', 
     pagerAnchorBuilder: function(idx, slide) { 
      // return sel string for existing anchor 
      return '#nav li:eq(' + (idx) + ') a'; 
     }, 
     before: function() { 
      // stop all inner slideshows 
      inners.cycle('stop'); 
      // start the new slide's slideshow 
      $(this).cycle({ 
       fx: 'scrollHorz', 
       speed: 'fast', 
       timeout: 0, 
       prev: '#prev', 
       next: '#next', 
       nowrap: 1, 
       after: function() { 
        $('#prev').removeClass('opac'); 
        $('#next').removeClass('opac'); 
        var countImg = $(this).siblings().size(); 
        if ($(this).index() == 0) $('#prev').addClass('opac'); 
        if ($(this).index() == countImg) $('#next').addClass('opac'); 
       } 
      }); 
     } 
    }); 
}); 

添加CSS透明度和jQuery和循環腳本鏈接,並能正常工作

問候,邁克爾

相關問題