我想知道如何使我的脚本仅将效果应用于当前悬停的列表项,而不是无序列表中的每个列表项。
脚本:
<script>
$(document).ready(function() {
// Initially hide
$("ul#navigation li div.chLeft,ul#navigation li div.chRight").hide();
// Show Effect
$("ul#navigation li").mouseenter(function(){
$("ul#navigation li div.chLeft,ul#navigation li div.chRight").show(function(){$(this).fadeIn(500);});
});
// Hide Effect
$("ul#navigation li").mouseleave(function(){
$("ul#navigation li div.chLeft,ul#navigation li div.chRight").hide(function(){$(this).fadeOut(100);});
});
});
</script>
加价:
<ul id="navigation">
<li><div class="chLeft"></div><div class="floatLeft"><a href="#">Link</a></div><div class="chRight"></div><div class="clear"></div></li>
<li><div class="chLeft"></div><div class="floatLeft"><a href="#">Link</a></div><div class="chRight"></div><div class="clear"></div></li>
<li><div class="chLeft"></div><div class="floatLeft"><a href="#">Link</a></div><div class="chRight"></div><div class="clear"></div></li>
<li><div class="chLeft"></div><div class="floatLeft"><a href="#">Link</a></div><div class="chRight"></div><div class="clear"></div></li>
<li><div class="chLeft"></div><div class="floatLeft"><a href="#">Link</a></div><div class="chRight"></div><div class="clear"></div></li>
</ul>
CSS:
#navigation{
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
list-style: none;
}
#navigation li{
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
line-height: 45px;
}
#navigation li a{
position: relative;
padding: 0 21px;
height: 45px;
color: #780507;
display: block;
outline: none;
text-decoration: none;
line-height: 90px;
font-family: Helvetica, Arial, sans-serif;
font-size: 16px;
text-shadow: 0px 0px 1px #430304;
letter-spacing: 1px;
}
.chLeft{
width: 30px;
height: 75px;
background: url('../img/sprite.png') -10px -5px no-repeat;
float: left;
}
.chRight{
width: 30px;
height: 75px;
background: url('../img/sprite.png') -100px -5px no-repeat;
float: left;
}
.floatLeft{
float: left;
}