我看到的第一个明显的事情是一个div
作为ul
的直接子。
即使这可能不会导致任何问题,那肯定是无效的HTML。大多数现代浏览器正在修复这......但仍然是一件坏事。
因此<ul id="slide_info">
内部的div
元素必须包含<li>
和</li>
。
然后,关于您的代码,您使用巧妙的appendTo
技巧来“循环”整个列表项......为什么不使用相同的技巧?
现在关于淡入/淡出...有动画延迟考虑。你可以使用回调函数,这些函数是在完成另一个函数时执行的函数。
$(document).ready(function(){
// Variable declarations
var slideCount = $('#slider ul li').length;
var slideWidth = $('#slider ul li').width();
var slideHeight = $('#slider ul li').height();
var sliderUlWidth = slideCount * slideWidth;
// Positionning
$('#slider').css({ width: slideWidth, height: slideHeight });
$('#slider ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });
// ??? Why this "re-ordering" on load?
$('#slider ul li:last-child').prependTo('#slider ul');
// Hide all slide-info item except the first
$("#slide_info li").not("#slide_info li:nth-child(1)").hide();
// Click handler
$('a.control_next').click(function() {
// Animate the slides
$('#slider ul').animate({
left: - slideWidth
}, 300, function() {
$('#slider ul li:first-child').appendTo('#slider ul');
$('#slider ul').css('left', '');
});
// Animate slide infos
// Get the visible one into a variable
var visible = $("#slide_info li:visible");
// Fade it out and fade in the next one
visible.fadeOut(300, function(){
// This is a callback, so after the fadeOut:
visible.next().fadeIn(300,function(){
// This is also a callback...
// "visible" is now faded out, but still in this variable.
// Append it to the end of the list.
visible.appendTo("#slide_info");
});
})
});
});
Your Fiddle updated
这工作得很好,是非常接近我想要去实现,现在我有一个更好的了解如何逻辑的。非常感谢你的精力。 – LGWJ