Try something like the following:

<div class="mobileclass" thru="class-state-one,class-state-two,class-
state-three"></div>

And the js:

$(function(){
   function rotateClass(){
      var el = $(this), classes = el.data('classes'), cur = el.data
('current-class'), next = cur++;
      if (next+1 > classes.length) next = 0;
      el.removeClass(classes[ cur ]).addClass(classes[ next ] ).data
('current-class', next);
   }
   var mobile = $('.mobileclass').each(function(){
      var el = $(this), classes = el.attr('thru').split(',');
      el.data('classes', classes).data('current-class', 0).bind
('rotate-class', rotateClass).addClass(classes[0]);
   });
   setInterval(function(){ mobile.trigger('rotate-class') }, 5000);
});

On Mar 21, 2:03 pm, mkmanning <michaell...@gmail.com> wrote:
> NaN is happening because of an error in this line:
>
> parseInt(div.className.substring(3));
>
> It most likely means your className is different.
>
> I just tested the code in Firefox on this markup and it works as it
> should:
>
> <div class="img1"></div>
>
> What does your html and js look like?
>
> On Mar 21, 7:21 am, Alexandru Dinulescu <alex.d.a...@gmail.com> wrote:
>
> > Hello.
>
> > I am getting a imgNaN when using this, can you tell me how i can make the
> > array script work since that doesnt work either.
>
> > -------------------
> > 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 Sat, Mar 21, 2009 at 4:13 AM, mkmanning <michaell...@gmail.com> wrote:
>
> > > 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