(function ($) { var current_pic = 0; var next_pic = 1; var totlalPic = 0; $(document).ready(function() { if($('.indexmiddle').hasClass('flash')){ totlalPic = $('.flash div.img div').children().length; $('.flash div.img div').each(function(i){ if($(this).index() == current_pic){ $(this).css({opacity:1}) $(this).stop().animate({left:-100,queue: true,opacity:1}, {duration:10000}, "easeInQuad"); }else{ $(this).css({opacity:0}) } }) setTimeout(function(){ $('.flash div.img div').imageChane(current_pic); }, 10100); } }) $.fn.imageChane = function(k){ $(this).each(function(i){ if($(this).index() == next_pic){ $(this).stop().css({left:0,"z-index":10}).animate({opacity:1},{duration:3000,easing:"easeInQuad",queue: true,complete:function(){ $(this).animate({left:-250},{duration:13000,easing:"easeInQuad",queue: true,complete:function(){ current_pic = next_pic; next_pic = next_pic +1; if(next_pic >= totlalPic){ next_pic = 0; } setTimeout(function(){ $('.flash div.img div').imageChane(current_pic); }, 100); }}); }}); }else if($(this).index() == current_pic){ $(this).css({opacity:1,"z-index":9}) }else{ $(this).css({opacity:0,"z-index":8}) } }) } })(jQuery);