/* * plugin:jquery.slideSwitchImg.js * version:1.0(2011.06.15) * requires:jQuery v1.3.2 later * author:Manabu Kushimoto(http://web-park.org) */ $(function(){ var $slideParentClass=$(".slideSwitchImg"),slideChildBlock="slideBlock"; $.fn.slideSwitchImg=function(){ var $t=$(this),$tChild=$("."+slideChildBlock,$t),childLength=$tChild.children().length,activeIndex=1,active="active", randomIndex=Math.floor(Math.random()*childLength),propety={ w:$t.width(), h:$t.height() }; $(">*",$tChild).eq(randomIndex).addClass(active); if(childLength==randomIndex+1){ $tChild.css({left:0+"px",width:(propety.w)*(childLength+1)+"px",height:propety.h+"px"}).show(function(){ $(">*",$tChild).not($(">*",$tChild).eq(randomIndex)).remove().clone(true).appendTo($tChild); }); }else{ $tChild.css({left:-(propety.w*randomIndex)+"px",width:(propety.w)*(childLength+1)+"px",height:propety.h+"px"}); } setSwitch=setInterval(function(){ var index=($tChild.children().index($("."+active,$tChild)))+1,nextElem=index+1; if(childLength<=index){ index=$tChild.children().index($("."+active,$tChild))-(childLength-1); $("."+active,$tChild).removeClass(active) $(">*:first",$tChild).addClass(active); }else{ $("."+active,$tChild).removeClass(active).next().addClass(active); } $tChild.animate({ left:-(propety.w*index)+"px" },500,function(){ if(childLength==index+1){ $tChild.css({left:0+"px"}).show(function(){ $(">*",$tChild).not($(">*",$tChild).eq(index)).remove().clone(true).appendTo($tChild); }); } }); },4000); }; $slideParentClass.each(function(){ $("
").addClass(slideChildBlock).append($(this).children()).appendTo(this); $(this).slideSwitchImg(); }); });