你必須在我看來兩個選項:
- 填充在頁面加載每個滑塊,jQuery的點擊功能動畫內容
- 使用AJAX調用
填充在每張幻燈片的基礎數據
如果它只是一些項目/幻燈片,那麼我會填充頁面加載。如果您正在查看大量幻燈片(您可能會期望每日新聞博客),或者如果每張幻燈片都包含大量數據(如高分辨率圖像等),則可以使用第二種方法。
第二個選項很容易做到。所有你需要的是三個div(一個用於屏幕幻燈片,兩個用於側面屏幕外幻燈片,當單擊任一箭頭時將'替換'屏幕上的幻燈片)。我會用這樣的:
<div class="container">
<div class="inner-container">
<div class="back"></div>
<div class="content off_screen_left" id="1"></div>
<div class="content on_screen" id="2"></div>
<div class="content off_screen_right" id="3"></div>
<div class="next"></div>
</div>
</div>
而且所需的CSS:
.container{width:200px;height:150px;overflow:hidden}
.inner-container{width:600px;height:150px;margin-left:-200px}
.content{float:left;width:200px;height:150px}
至於jQuery的:
$(".next").live('click', function(){
var current_id=$(this).prev(".on_screen").attr("id"); // get current page ID
$(".content").css("float","right"); // float all elements to the right
$(".off_screen_right").animate({display:none;}); // make the furthest right disappear gradually
$(".on_screen").attr("class","off_screen_right"); // make on_screen the new off_screen_right and add the correct ID attribute
$(".off_screen_left").attr("class","content on_screen"); // make off_screen_left the new on_screen
$(".container").prepend('<div class="content off_screen_left" id="'+current_id-1+'"></div>'); // add the new off_screen_left element and add the correct ID attribute
$(".off_screen_left").load("load-content.php?page_id="+current_id-1); // populate the new off_screen_left element
});
$(".back").live('click', function(){
var current_id=$(this).next(".on_screen").attr("id"); // get current page ID
$(".content").css("float","left"); // float all elements to the left
$(".off_screen_left").animate({display:none;}); // make the furthest left disappear gradually
$(".on_screen").attr("class","off_screen_left"); // make on_screen the new off_screen_left and add the correct ID attribute
$(".off_screen_right").attr("class","content on_screen"); // make off_screen_right the new on_screen
$(".container").append('<div class="content off_screen_right" id="'+current_id+1+'"></div>'); // add the new off_screen_left element and add the correct ID attribute
$(".off_screen_right").load("load-content.php?page_id="+current_id+1); // populate the new off_screen_left element
});
但是,這只是一個選項。你可以使用滑塊開箱即用,但我更喜歡定製代碼,以便我確切地知道我在做什麼。
p.s.我意識到這會打破書籤標籤,但我計劃實施HTML5的歷史API(或者history.js ...)。 – neokio