我想創建一個翻轉內容橫幅。我設法找到一個與我想要的幾乎相似的東西,但仍然有我想要的東西。是否可以在沒有播放按鈕的情況下進行自動播放,並且是否可以在到達最後一張幻燈片時保持幻燈片效果。有沒有人可以幫忙?我 http://jsfiddle.net/4q3GZ/342/向左滑動內容橫幅
$(document).ready(function() {
var height = 300,
width = 600,
tabs = 3,
$tabs = $('.tab'),
contentNum = 1,
delay = 2000, // time in milliseconds to pause between tabs
timer;
$('.play').click(function() {
var $t = $(this);
if($t.hasClass('playing')) {
// stop
clearTimeout(timer);
$t.removeClass('playing').html('play');
} else {
// play
timer = setInterval(function() {
contentNum++; // change to contentNum--; to go left
if(contentNum > tabs) {
contentNum = 1;
} // loop right
if(contentNum < 1) {
contentNum = tabs;
} // loop left
$tabs.eq(contentNum - 1).find('a').trigger('click');
}, delay);
$t.addClass('playing').html('stop');
}
});
$('.main_inner').css({
width: tabs * width
});
$('a.tab_link').click(function() {
$tabs.filter('.active').removeClass('active');
$(this).parent().addClass('active');
// make sure contentNum is a number and not a string
contentNum = parseInt($(this).attr('rel'), 10);
$('.main_inner').animate({
marginLeft: '-' + (width * contentNum - width)
}, 600);
return false;
});
$('.previous a').click(function() {
if(contentNum > 1) {
// find previous tab, trigger a click on the link
// subtract 2 because eq() uses zero based index
$tabs.eq(contentNum - 2).find('a').trigger('click');
}
return false;
});
$('.next a').click(function() {
if(contentNum < tabs) {
// find next tab, trigger a click on the link
// contentNum doesn't need + 1 because it is +1 relative to eq()
// which is a zero based index
$tabs.eq(contentNum).find('a').trigger('click');
}
return false;
});
});
你寫了這段代碼嗎? – kirugan 2013-03-16 05:14:28
在Google上搜索一個jQuery滑塊.. – john 2013-03-16 05:15:01
'是否可以在沒有播放按鈕的情況下自動播放?嚴重的是,每隔幾秒鐘調用一次'click'函數。 – 2013-03-16 05:16:32