假设您的基本标记如下所示:
<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");
}
});
像这样的东西,或者像这样建模的东西应该可以工作。