网站 - 根据鼠标位置更改图像(2 个区域)
Website - Change image depending on mouse position (2 zones)
我有以下情况很简单(1页,3个区域:左 - 中 - 右):
.HTML:
<div class="page">
<div class="answerswer-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="answerswer-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将鼠标悬停在图片上,但是我找不到此问题的解决方案。
提前谢谢你!
为每个区域分配一个 id:
<div class="answerswer-on-the-right-or-left" id="leftZone">Left Zone</div>
<div class="answerswer-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');
});
相关文章:
- 不能在图像中的地图标记中使用花式框jquery插件的区域标记
- 如何使用JavaScript/jQuery选择图像的多边形区域
- 如何将 ng-repeat 与图像映射区域标签一起使用
- 如何在文件打开和调用图像区域选择时获取原始图像大小
- 地图<区域>未显示背景图像
- 如何创建具有滚动背景图像的可滚动文本区域
- 用于图像上映射区域的Bootstrap Popover/Tooltip
- Javascript(或jquery)来获取文本区域值的每个图像标记
- 缩小后的大图像上的Jcrop圆形选择显示预览选择区域中的全尺寸图像
- 任何比较两个不同位图图像并在javascript中检测不同区域的方法
- 是否可以使用图像数据设置画架命中区域
- 获取图像可见区域状态,以在画布中将图像设置在先前拖动的位置
- 单击以将所有图像 HTML 标记插入到文本区域
- 图像映射区域无法触发单击事件.afer最大化寡妇或恢复窗口单击事件触发
- 如何使绝对定位的图像区域地图可以用鼠标点击
- 响应式图像区域地图与螺旋菜单冲突
- 高亮显示图像区域-单击链接时
- 当我的模态窗口关闭时,从图像中删除图像区域选择
- 在HTML5图像画布中裁剪图像区域
- 从主图像区域打开fancybox中的特定图像