基本的なマークアップが次のようになっていると仮定します。
<div id="div1" class="myClass"><a href="#">Div1</a></div>
<div id="div2" class="myClass"><a href="#">Div2</a></div>
<div id="div3" class="myClass"><a href="#">Div3</a></div>
あなたはこれを行うことができます:
// Mouseover event
$(".myClass a").live("mouseover", function () {
// If it already has the "selected" class applied to it, do nothing
if ( $(this).is(".selected") ) {
return;
}
else {
// Do your hover effect
$(this).animate({height: "30px"}, 200);
}
});
// Mouseout event
$(".myClass a").live ("mouseout", function () {
// If it already has the "selected" class applied to it, do nothing
if ( $(this).is(".selected") {
return;
}
else {
// Do your mouseout effect (return to default state or whatever else)
$(this).animate({height: "20px"}, 200);
}
});
// Click Event
$(".myClass a").live("click", function () {
// If it already has the "selected" class applied to it, do nothing
if ( $(this).is(".selected") ) {
return;
}
else {
// Remove the selected class from any element that already has it
$(".selected").removeClass(".selected");
$(this).addClass("selected");
}
});
このようなもの、またはこのようにモデル化されたものが機能するはずです。