我想添加第二個尋呼機到我的幻燈片1/3>格式,所以如果有3張幻燈片,它顯示了多少幻燈片和什麼滑動你的,如果你想向前移動你只需點擊箭頭。它必須很簡單,但我找不到任何例子。這是我到目前爲止:添加第二個尋呼機到jquery循環幻燈片
$(function() {
$('.slideshow').each(function() {
var $nav = $('<div class="nav"></div>').insertAfter(this);
var $nav2 = $('<div class="nav2"></div>').insertBefore(this);
$('<div class="caption"> </div>').insertAfter($nav);
$(this).cycle({
fx: 'fade',
speed: 300,
timeout: 0,
pager: $nav,
after: onAfter
});
});
function onAfter(curr, next, opts) {
var src = ' ';
if (next.src)
src = next.src.match(/([a-zA-Z0-9\.]+$)/)[1];
$(curr).parent().nextAll('div.caption:first').html(src);
}
任何想法?
更新: 謝謝,傑夫羔羊...我試過了,它幾乎在那裏。因爲我在一個頁面上有兩個幻燈片,所以導航是疊加在一起的,所以如果我繼續前進,那麼兩個字幕都會改變。我試圖改變類名,但它仍然疊加。我在這裏錯過了什麼?這裏是我更新的代碼:
$(function() {
$('.slideshow').each(function() {
var $nav = $('<div class="nav"></div>').insertAfter(this);
var $nav2 = $('<div class="nav2"></div>').insertBefore(this);
$('<div class="caption"> </div>').insertBefore($nav);
$('<div class="caption2"> </div>').insertAfter($nav2);
$('.next').click(function() {
$('.slideshow').cycle('next');
});
$('.next2').click(function() {
$('.two').cycle('next');
});
$(this).cycle({
fx: 'fade',
speed: 300,
timeout: 0,
pager: $nav,
after: onAfter
});
});
function onAfter() {
$('.caption').html('<h3>' + (parseInt($(this).index())+1) + '/' + $(".slideshow div").length + '</h3>');
}
function onAfter() {
$('.caption2').html('<h3>' + (parseInt($(this).index())+1) + '/' + $(".two div").length + '</h3>');
}
如果需要,我想要添加第三個幻燈片的選項。這是我的HTML:
<div class="slideshow-container">
<h2>CASE STUDIES</h2>
<input type="button" class="next" value=">" />
<div class="slideshow">
<div> <img src="images/jorge-pensi.png" width="278" height="270" />
<h1>Jorge<br/>
<strong>Pensi</strong></h1>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
<p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p>
</div>
<div> <img src="images/jorge-pensi.png" width="278" height="270" />
<h1>Designer<br/>
<strong>Two</strong></h1>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
<p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p>
</div>
</div>
</div>
<div class="slideshow-container">
<h2>OUR DESIGNERS</h2>
<input type="button" class="next2" value=">" />
<div class="slideshow two">
<div> <img src="images/jorge-pensi.png" width="278" height="270" />
<h1>Jorge<br/>
<strong>Pensi</strong></h1>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
<p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p>
</div>
<div> <img src="images/jorge-pensi.png" width="278" height="270" />
<h1>Designer<br/>
<strong>Two</strong></h1>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
<p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p>
</div>
關於更新:您對兩個幻燈片都調用了相同的'onAfter'函數。除非您想將此擴展爲超過2個幻燈片,否則請勿執行.each(),並且只需單獨配置每個幻燈片。此外,很難弄清楚你所得到的,因爲你不包括HTML。 – 2012-03-16 20:29:55
下次你應該提問整個問題。這樣,那些回答的人不需要重寫他們的代碼... – 2012-03-16 20:43:02
你是對的。我很抱歉。 – doitliketyler 2012-03-16 20:47:10