你必须在我看来两个选项:
- 填充在页面加载每个滑块,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