【发布时间】:2014-03-03 03:03:29
【问题描述】:
我正在尝试在 3 个 div 之间进行淡入淡出旋转,当前代码:
$(window).load(function(){
var div1 = $("#apDiv1");
var div2 = $("#apDiv2");
function fade() {
div1.stop(true, true).fadeIn(2000);
div2.stop(true, true).fadeOut(2000, function() {
// swap in/out
var temp = div1;
div1 = div2;
div2 = temp;
// start over again
setTimeout(fade, 1000);
});
}
// start the process
fade(); })
这适用于 2 个 div,但是否可以在旋转中插入第三个?
我试过这样:
$(window).load(function(){
var div1 = $("#apDiv1");
var div2 = $("#apDiv2");
var div3 = $("#apDiv3");
function fade() {
div1.stop(true, true).fadeIn(2000);
div2.stop(true, true).fadeOut(2000);
div3.stop(true, true).fadeIn(2000);
div1.stop(true, true).fadeOut(2000, function() {
// swap in/out
var
temp = div1
div1 = div2;
div2 = div3;
div3 = div1;
div1 = temp
// start over again
setTimeout(fade, 1000);
});
}
// start the process
fade(); })
但这只是跳过它/根本不起作用。
【问题讨论】:
-
你正在丢失/覆盖
div1,然后当它重新分配到 3 时,它又回到了第 2 位! =] 将div1保存为临时变量,以便在最后再次使用。 -
这可能会有所帮助:stackoverflow.com/a/10194920/1823841
标签: jquery