I have one image with 9 different states and corresponding background position rules set as classes for displaying different states. I cannot use the: hover pseudo-selector because the mutable background image is not the same element that is hanging. I defined classes as follows:
#chooser_nav {width:580px; height:38px; background:transparent url(/assets/images/chooser-tabs.jpg) 0 0 no-repeat; margin-left:34px;}
#chooser_nav.feat {background-position:0 0;}
#chooser_nav.inv {background-position:0 -114px;}
#chooser_nav.bts {background-position:0 -228px;}
#chooser_nav.featinv {background-position:0 -38px;}
#chooser_nav.featbts {background-position:0 -76px;}
#chooser_nav.invfeat {background-position:0 -152px;}
#chooser_nav.invbts {background-position:0 -190px;}
#chooser_nav.btsfeat {background-position:0 -266px;}
#chooser_nav.btsinv {background-position:0 -304px;}
Then, using jQuery, I have a series of hover rules based on a previous click event (the unedited "cur" variable is properly declared elsewhere):
$("#featured_races a").hover(function(){
cur == "feat" ? $("#chooser_nav").attr("class", cur) : $("#chooser_nav").attr("class", cur+"feat");
}, function(){
$("#chooser_nav").attr("class", cur);
});
$("#invitational_races a").hover(function(){
cur == "inv" ? $("#chooser_nav").attr("class", cur) : $("#chooser_nav").attr("class", cur+"inv");
}, function(){
$("#chooser_nav").attr("class", cur);
});
$("#behind_the_scenes a").hover(function(){
cur == "bts" ? $("#chooser_nav").attr("class", cur) : $("#chooser_nav").attr("class", cur+"bts");
}, function(){
$("#chooser_nav").attr("class", cur);
});
, Moz WebKit . , . IE7. IE6 . , DOM MS -. , jQuery . , .
... , Crackoverflow... ...
EDIT:
className vs. setAttribute... . attr ( "class", cur) . , , ... .
2:
jQuery- : , . , , ... , . , , , - CSS, ...