此代码适用于 FF、Safari、Chrome 和 IE9,但在 9 之前的 IE 中不能 100% 运行。图像的淡入淡出有效,但是当我尝试更改代码悬停部分的文本颜色时不起作用。它让我相信这是代码的 .attr 部分的问题?
我确信有更好的方法可以做到这一点,因此我们将不胜感激。
编辑:当我将鼠标悬停在图像上时,第二个 div 中的文本应该会改变颜色。然后,当我将鼠标移出时,文本颜色应该会再次改变。
这是我的javascript代码:
<script>
$(document).ready(function(){
$("#boxes li img").fadeTo("fast", 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads
$("#text-boxes li").css("color","#f2f2f4");
$("#boxes li img").hover(function(){
$(this).fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
var id = $(this).attr("id");
$("#text-boxes li#"+id).css("color","#333333");
},function(){
$(this).fadeTo("fast", 0.6); // This should set the opacity back to 60% on mouseout
$("#text-boxes li").css("color","#f2f2f4");
});
});
</script>
这是我的html代码:
<img src="images/where.png" alt="where would you like to visit first?" /><br>
<ul id="boxes">
<li><a href="#"><img id="a" src="images/mom-stories.jpg" /></a></li>
<li><a href="#"><img id="b" src="images/mom-stories.jpg" /></a></li>
<li><a href="#"><img id="c" src="images/mom-stories.jpg" /></a></li>
<li><a href="#"><img id="d" src="images/mom-stories.jpg" /></a></li>
<li><a href="#"><img id="e" src="images/mom-stories.jpg" /></a></li>
<li><a href="#"><img id="f" src="images/mom-stories.jpg" /></a></li>
</ul>
<div style="width:100%;height:80px;background:#f2f2f4;overflow:auto;">
<ul id="text-boxes" style="padding-top:15px;">
<li id="a" style="width:147px;text-align:center;">Real mom's sharing<br>real experiences<br>in parenting</li>
<li id="b" style="width:147px;text-align:center;">Real mom's sharing<br>real experiences<br>in parenting</li>
<li id="c" style="width:147px;text-align:center;">Real mom's sharing<br>real experiences<br>in parenting</li>
<li id="d" style="width:147px;text-align:center;">Real mom's sharing<br>real experiences<br>in parenting</li>
<li id="e" style="width:147px;text-align:center;">Real mom's sharing<br>real experiences<br>in parenting</li>
<li id="f" style="width:147px;text-align:center;">Real mom's sharing<br>real experiences<br>in parenting</li>
</ul>
</div>