经过一番研究,下面的代码应该可以正常更改图像源,但不是吗?
$("#li_1").mouseover(function () {
$(this).attr("src", "images/hover_12.png");
}, function () {
$(this).attr("src", "images/ori_12.png");
});
HTML 代码:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="demo.css">
<style>
li{
display: block;
}
</style>
</head>
<body>
<div id='wrap'>
<div id="clickable_div">MENU</div>
<div id="nav_menu">
<ul class="dropDown">
<li id="li_1"><img src="images/ori_12.png"></li>
<li id="li_2"><img src="images/ori_14.png"></li>
<li id="li_3"><img src="images/ori_15.png"></li>
<li id="li_4"><img src="images/ori_16.png"></li>
</ul>
</div>
</div>
</div>
</body>
<script>
$("#li_1").mouseover(function () {
$(this).attr("src", "images/hover_12.png");
}, function () {
$(this).attr("src", "images/ori_12.png");
});
$('#wrap').mouseover( function(){
$('#nav_menu').slideDown();
});
$('#wrap').mouseleave( function(){
$('#nav_menu').slideUp();
});
</script>
</html>
演示.CSS:
#clickable_div {width:166px; background-color:#9c9c9c;}
*{margin:0; padding:0}
#nav_menu{width:166px; height:auto; background-color:#CCC;display:none;}
#wrap{ width:166px }
这个想法很简单。我试图将鼠标悬停在一个元素上并有一种下拉感觉来列出项目,并且对于我悬停的每个项目,图像li
将被替换。