这是一个jsfiddle 显示你想要什么(我认为)。 Html 就是你展示的。
JavaScript:
(function ($) {
function fadeOut(div, sel) {
var next;
next = div.next(sel);
next = next.length ? next : $(sel + ':first');
return function () {
div.fadeTo(2000, 0, fadeIn(next, sel));
}
}
function fadeIn(div, sel) {
return function () {
div.fadeTo(2000, 1, fadeOut(div, sel));
}
}
$.fn.fadeInNOut = function (sel) {
$(this).find(sel + ':first').fadeTo(0, 1);
fadeOut($(sel + ':first'), sel)();
return this;
};
}(jQuery));
$('body').fadeInNOut('div');
CSS(看看发生了什么):
div {
position : absolute;
top : 0;
left : 0;
opacity : 0;
border : 1px solid rgb(0, 0, 0);
color : rgb(255,255,255);
display : inline;
font-size : 50px;
float : left;
height : 150px;
line-height : 150px;
margin : 10px;
text-align : center;
width : 200px;
}
#section1 {
background : rgb(255,0,0);
}
#section2 {
background : rgb(0,255,0);
}
#section3 {
background : rgb(0,0,255);
}