Another alternative (no array needed, goes from img1 to img5 and
starts over):

$(document).ready(function(){
        div = $('div.img1')[0], //get with whatever selector once
        swapDiv = setInterval(function(){
                n = parseInt(div.className.substring(3));
                div.className = 'img'+( n>4?1:n+1 );
        },5000);
});

If you want to stop it later, just call clearInterval('swapDiv');
It's probably a little more efficient :)

On Mar 20, 12:23 pm, Alexandru Dinulescu <alex.d.a...@gmail.com>
wrote:
> Hello.
>
> Can i call this function normally like
> function imageSwap(){
> function code goes in here
>
> }
>
> $(document).ready(imageSwap);
> ?
>
> And another question
> can i put in the array paramters and have variables declared at the top
> for ex is this correct?
>
> function imageSwap() {
> var img1 = classImg1
> var img2 = classImg2
> var img3 = classImg3
>
> var imgArray = [ "img1" , "img2", "img3"];
>
> function swap(i){
>    if(imgArray.length > i){
>        $('.' + imgArray[i]).removeClass(
>
>
>
> > imgArray[i]).addClass(imgArray[i+1]);
> >    }else{
> >        return;
> >    }
> > setTimeout("swap("+(i+1)+")", 5000);
> > }
>
> > // Call the function
> > swap(0);
>
> }
>
> $(document).ready(imageSwap);
> -------------------
> Alexandru Dinulescu
> Web Developer
> (X)HTML/CSS Specialist
> Expert Guarantee Certified Developer
> XHTML:http://www.expertrating.com/transcript.asp?transcriptid=1879053
> CSS :http://www.expertrating.com/transcript.asp?transcriptid=1870619
> RentACoder 
> Profile:http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInf...
>
> MainWebsite:http://alexd.adore.ro
>
> On Fri, Mar 20, 2009 at 2:39 PM, jQuery Lover <ilovejqu...@gmail.com> wrote:
>
> > The code is not perfect:
>
> > var imgArray = [ "img1" , "img2", "img3"];
>
> > function swap(i){
> >    if(imgArray.length > i){
> >        $('.' +
> > imgArray[i]).removeClass(imgArray[i]).addClass(imgArray[i+1]);
> >    }else{
> >        return;
> >    }
> > setTimeout("swap("+(i+1)+")", 5000);
> > }
>
> > // Call the function
> > swap(0);
>
> > ----
> > Read jQuery HowTo Resource  -  http://jquery-howto.blogspot.com
>
> > On Fri, Mar 20, 2009 at 5:15 PM, Alexandru Dinulescu
> > <alex.d.a...@gmail.com> wrote:
> > > Hello.
>
> > > I have a huge question. I need something that rotates classes each 5
> > seconds
> > > for ex
>
> > > I have a <div class="img1"> </div>. I want each 5 seconds the class to be
> > > changed from img1 to img2, and so on so at the start an array should be
> > > placed like
> > > imgArray = [ "img1" , "img2", "img3",  etc ]
>
> > > I need css classes changed not a plain image since  the image is a
> > > background image and i have text on it.
>
> > > I did look over google but i couldnt find any help regarding this matter.
>
> > > Thank you
>
> > > -------------------
> > > Alexandru Dinulescu
> > > Web Developer
> > > (X)HTML/CSS Specialist
> > > Expert Guarantee Certified Developer
> > > XHTML:http://www.expertrating.com/transcript.asp?transcriptid=1879053
> > > CSS :http://www.expertrating.com/transcript.asp?transcriptid=1870619
> > > RentACoder Profile:
>
> >http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInf...
>
> > > MainWebsite:http://alexd.adore.ro

Reply via email to