你可以在這裏查看我的自定義滑塊:http://www.awaismuzaffar.com/examples/index.html幫助修改我的自定義JQuery的滑塊允許連續滾動
而且下面是它的jQuery代碼:
$(document).ready(function() {
// Slider Function
var slideWidth = $('div.slide').width();
// Set the left position of each div element
$('div.slide').each(function(index){
$(this).css('left', index * slideWidth); // Multiply each div element by the index(0, 1 etc) so each div is placed inline
});
// Next step is to animate the div elements
var clickCount = 1;
var slideCount = $('div.slide').length;
// Set the previous button to hide when loading with the first slide
if(clickCount == 1){
$('a#previous-button').css('background-color', '#cccccc');
}
$('a#next-button').click(function() {
if(clickCount < slideCount) {
$('div.slide').animate({"left":"-=" + slideWidth}, 'slow');
$('a#previous-button').css('background-color', '#ffffff');
clickCount++;
}
if(clickCount == slideCount) {
$('a#next-button').css('background-color', '#cccccc'); // Hide or grey out button
}
});
$('a#previous-button').click(function() {
if(clickCount > 1){
$('div.slide').animate({"left":"+=" + slideWidth}, 'slow');
$('a#next-button').css('background-color', '#ffffff');
clickCount--;
}
if(clickCount == 1){
$('a#previous-button').css('background-color', '#cccccc'); // Hide or grey out button
}
});
});
我想修改該滑塊允許連續滾動。
我不確定如何實現這一點,我假設我需要使用append,但我不知道如何使用它。
謝謝。
甚至更好:嘗試使滑塊從當前位置移動到目標(n),而不管它的位置,不僅從n到n + 1。這樣,你就可以從5滾動到1而不附加或更換DOM – 2011-04-07 21:19:02