[英]jQuery fade in/out between divs
I have this code: 我有以下代码:
var next = null;
var outer = jQuery('.banner .container');
var current = outer.find('.banner-word:first');
current.fadeIn();
function fade() {
if (current.next('div.banner-word').length > 0) {
next = current.next('div.banner-word');
} else {
next = outer.find('.banner-word:first');
}
current.fadeOut();
next.fadeIn();
current = next;
setTimeout(fade, 11000);
}
// start the process
fade();
A few problems with it - 1) It seems to ignore the first banner-word div 2) On load it shows quickly shows the first 2 banner-word divs and then starts with the second banner-word div 它有一些问题-1)似乎忽略了第一个标题词div 2)在加载时它迅速显示了前2个标题词div,然后以第二个标题词div开始
Am I missing something obvious? 我是否缺少明显的东西?
Try changing: 尝试更改:
if (current.next('div.banner-word').length > 0) {
next = current.next('div.banner-word');
} else {
next = outer.find('.banner-word:first');
}
to: 至:
if (current.next().is('div.banner-word')) {
next = current.next();
} else {
next = outer.find('.banner-word:first');
}
Edit: try adding a delay to the initial fade() call. 编辑:尝试向初始fade()调用添加延迟。 Change
更改
fade();
to 至
setTimeout(fade, 5000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.