我有以下情况非常简单(1页,3个区:左 - 中 - 右):
HTML:
<div class="page">
<div class="answer-on-the-right-or-left">
Left zone
</div>
<div class="picture-in-the-middle">
<img src="@Url.Content("/content/images/qres/faceblackandwhite.png")"/>
</div>
<div class="answer-on-the-right-or-left">
Right zone
</div>
</div>
CSS:
.page { width: 800px; height: 500px; }
.answer-on-the-right-or-left { float: left; width : 300px; height: 500px; }
.picture-in-the-middle { float: left; width : 150px; height: 500px; }
我想做以下事情:
"/content/images/qres/facecolorleft.png"
"/content/images/qres/facecolorright.png"
"/content/images/qres/faceblackandwhite.png"
我知道如何使用javascript对图片进行鼠标悬停,但我找不到解决此问题的方法。
提前谢谢!
答案 0 :(得分:1)
为每个区域分配一个ID:
<div class="answer-on-the-right-or-left" id="leftZone">Left Zone</div>
<div class="answer-on-the-right-or-left" id="rightZone">Right Zone</div>
并绑定悬停
$('.answer-on-the-right-or-left').hover(function() {
var id = $(this).attr('id');
var img = $('.picture-in-the-middle img');
if(id == 'leftZone') img.attr('src', '/content/images/qres/facecolorleft.png');
else if(id == 'rightZone') img.attr('src', '/content/images/qres/facecolorright.png');
}, function() {
$('.picture-in-the-middle img').attr('src', '/content/images/qres/faceblackandwhite.png');
});