Jquery FadeIn,FadeOut然后对另一个图像执行相同的操作
我想淡入淡出图像,等待几毫秒,淡出图像,我想用几张图像来做这个,我也想循环这个。我的想法是对每个循环执行此操作,但它不起作用。我写道:Jquery FadeIn,FadeOut然后对另一个图像执行相同的操作,jquery,Jquery,我想淡入淡出图像,等待几毫秒,淡出图像,我想用几张图像来做这个,我也想循环这个。我的想法是对每个循环执行此操作,但它不起作用。我写道: function showDiv() { if($('.header_img a:not(:contains(shown))').length) { var current = ($('.header_img a:not(:contains(shown)):first')); $(current).fadeIn(1500)
function showDiv() {
if($('.header_img a:not(:contains(shown))').length) {
var current = ($('.header_img a:not(:contains(shown)):first'));
$(current).fadeIn(1500).delay(4000).fadeOut(1500);
$(current).addClass('shown');
setTimeout(showDiv, 1000);
}
}
showDiv();
编辑:
非常感谢所有的答案:)然而,我自己做了一些事情:
$(document).ready(function(){
var current = ($('.header_img a:first-child'));
var counter = 0;
var n = $(".header_img a").length;
function showDiv(current) {
if(counter<n-1 )
{
counter++;
$(current).fadeIn(1500).delay(4000).fadeOut(1500, function(){
current=$(current).next();
showDiv(current);
})
}
else{
counter = 0;
$(current).fadeIn(1500).delay(4000).fadeOut(1500, function(){
current=($('.header_img a:first-child'));
showDiv(current);
})
}
}
showDiv(current);
});
$(文档).ready(函数(){
当前变量=($('.header_img a:first child');
var计数器=0;
变量n=$(“.header\u img a”).长度;
函数showDiv(当前){
如果(计数器)可以在动画完成时指定回调:请尝试此操作
var fader = {
init: function() {
this.firstLi = jQuery('#images ul li:first').attr('id');
this.lastLi = jQuery('#images ul li:last').attr('id');
},
doFade: function() {
this.currID = jQuery('#images ul').data('currLI');
this.currLiStr = '#images ul li#' + fader.currID;
this.nextID = (this.currID == this.lastLi) ? this.firstLi : jQuery(fader.currLiStr).next().attr('id');
this.nextLiStr = jQuery('#images ul li#' + fader.nextID);
jQuery(fader.currLiStr).fadeOut(3000);
jQuery(fader.nextLiStr).fadeIn(2000);
jQuery('#images ul').data('currLI',fader.nextID);
}
}
被称为:
var firstLi = jQuery('#images ul li:first').attr('id');
jQuery('#images ul').data('currLI',firstLi);
fader.init();
setInterval('fader.doFade()',10000);
}