我在jQuery中有这个代码:
function lshow() {
var delayt = 500;
var showtime = 5000;
var ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
var i=0;
$.each(ArrayOfElements,function (i,element) {
if($(element).is(':visible')) {
$(element).delay(delayt).hide('slow');
}
if ($(element).is(':hidden')) {
$(element).delay(showtime).show('slow');
}
});
}
和HTML:
<span class="slogan">
<span class="slogan1">my slogan</span><!--Default visible-->
<span class="whatwedo"><!--Default invisible-->
projects <span class="sm">and modernization </span> of something <span class="ekon">fine</span>
<span class="ene">fast</span>
<span class="ekol">smooth</span>
</span>
</span>
CSS:
.whatwedo, .sm, .ene, .ekol {
display: none;
}
我想将它设置为:
淡出
“fine”fadeOut“fast”fadeIn
同样的事情
但是5秒后。表明 “项目和现代化的精细快速smoth” 我无法让它工作
答案 0 :(得分:5)
试试这个http://jsfiddle.net/Kt38f/
$(document).ready(function() {
var delayt = 500;
var showtime = 5000;
var ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
var i=0;
$('.slogan1').fadeOut(delayt, function(){
$(".whatwedo").fadeIn(showtime , function(){
$('.ekon').fadeOut(showtime , function(){
$('.ene').fadeIn(showtime, function(){
$('.ene').fadeOut(showtime, function(){
$('.ekol').fadeIn(showtime, function(){
$('.sm').fadeIn(showtime);
});
});
});
});
});
});
});
答案 1 :(得分:1)
这是另一种方式:
不是将元素放在数组中,而是将应该在数组中执行的函数放入并使用setTimeout
处理它:
function lshow() {
var intv = 5000;
var funcs = [
function() {
$('.slogan1').hide('slow');
$('.whatwedo').show('slow');
},
function() {
$('.ekon').hide('slow');
$('.ene').show('slow');
},
function() {
$('.ene').hide('slow');
$('.ekol').show('slow');
},
function() {
$('.sm').show('slow');
}
];
var i = 0;
setTimeout(function() {
var func = funcs[i];
if(func) {
i++;
func();
setTimeout(arguments.callee, intv);
}
}, intv);
}
答案 2 :(得分:1)
我采取了一些不同的方法。小提琴@ http://jsfiddle.net/SinS3i/xwc9a/1/
var currentStep = false;
var t = false;
ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
var delayt = 500;
var showtime = 5000;
lshow = function(elements) {
var lastStep = currentStep;
currentStep = elements.shift();
var hideIt = lastStep ? $(lastStep).has(currentStep).length === 0 : false;
if(hideIt) {
$(lastStep).fadeOut(showtime, function() {
$(currentStep).fadeIn(showtime, function() {
t = ArrayOfElements.length > 0 ? setTimeout("lshow(ArrayOfElements)", delayt) : false;
});
});
} else {
$(currentStep).fadeIn(showtime, function() {
t = ArrayOfElements.length > 0 ? setTimeout("lshow(ArrayOfElements)", delayt) : false;
});
}
};
$(document).ready(function(){
t = setTimeout("lshow(ArrayOfElements)", delayt);
});
答案 3 :(得分:0)