Using jQuery UI switchClass method to change class of 13 elements at once? -
i have 13 different elements following class on of these elements defined candidate
now have 13 different classes these same elements defined well, such follows:
can1
, can2
, can3
, can4
, can5
, can6
, can7
, can8
, can9
, can10
, can11
, can12
, can13
i need switch each elements class simultaneously @ same time once every 5 seconds or so, keep candidate
class defined on of them, need change can
classes. , need change classes decrement 1 every 5 seconds, except when can1 defined, switch can13 instead. so...
can1 becomes can13 can2 becomes can1 can3 becomes can2 , on... way can13 becomming can12
and during class change, needs animate class well, i'm thinking need switchclass
accomplish this. what's best , productive way exactly?
could grab elements in 1 go using:
$(".candidate").switchclass(... code);
but i'm screwed getting old class , changing new class, how that?
also, have defined data-class
on each element actual number represents can
class. so, if element has class of can1
, data-class
has value of 1
, if element has class of can2
, data-class
on element has value of 2
, , on...
how can use advantage , decrement can
classes last number value every 5 seconds? noticed switchclass
method can have queue
option set false
want, again, how use purpose?? , wanting 500 ms animation of switchclass
do have .each()
on this?
it better if classes ranged 0 12 instead of 1 13. way can use modular arithmetic. if have 1 13, addition after computing modulus, i.e., nextclassid = (currentclassid % 13) + 1;
(but seems more confusing me).
setinterval(function() { $('.candidate').each(function() { var $this = $(this), currentclassid = number($this.data('class')), nextclassid = (currentclassid + 1) % 13; $this.switchclass('can' + currentclassid, 'can' + nextclassid); $this.data('class', nextclassid); }); }, 5000);
working fiddle, http://jsfiddle.net/7dyxh/
Comments
Post a Comment