【发布时间】:2012-06-06 13:45:22
【问题描述】:
我目前正在尝试将鼠标悬停在背景图片上并在单独的 div 中查看新图片。哪个有效(使用下面的代码),但是单击图像时我似乎无法更改它。下面是代表我要完成的工作的图像。
1 http://pkg.madisonmottdev.com/images/1.png
悬停或点击时(2 楼相同) 2 http://pkg.madisonmottdev.com/images/2.png
当前用于悬停的Javascript代码,可以正常工作。我只是不知道如何单击(一楼或二楼并在右侧更改)。任何帮助表示赞赏。
$(window).load(function(){
$(document).ready(function(){
// FIRST FLOOR
$('.floor1').mouseover(function(){
$('.floor1').css('background', 'url("images/phase-2/first-floor-hover.a.png") no-repeat');
$('#elevation').css('background', 'url("images/phase-2/first-floor-lg.a.png") no-repeat');
});
$('.floor1').mouseout(function(){
$('.floor1').css('background', 'url("images/phase-2/first-floor.a.png") no-repeat');
$('#elevation').css('background', 'url("images/phase-2/elevation.a.png") no-repeat');
});
// SECOND FLOOR
$('.floor2').mouseover(function(){
$('.floor2').css('background', 'url("images/phase-2/second-floor-hover.a.png") no-repeat');
$('#elevation').css('background', 'url("images/phase-2/second-floor-lg.a.png") no-repeat');
});
$('.floor2').mouseout(function(){
$('.floor2').css('background', 'url("images/phase-2/second-floor.a.png") no-repeat');
$('#elevation').css('background', 'url("images/phase-2/elevation.a.png") no-repeat');
});
});
});
HTML 代码(地板 1、地板 2 和高程设置为具有高度/宽度的背景图像):
<div id="building">
<div id="floor">
<div class="floor1"></div>
</div>
<div id="floor">
<div class="floor2"></div>
</div>
</div>
【问题讨论】:
-
你能设置一个测试用例来显示问题吗?最好在jsfiddle.net?
-
另外,您的点击事件函数不起作用也很高兴看到。
-
您想要的行为似乎有点奇怪,因为鼠标悬停事件总是在用户有机会点击图像之前发生。
-
嗨,事实-我想完全做到这一点jsfiddle.net/neo108/fCsNN,但我想添加一个功能,您单击其中一个框,它会一直存在,直到您单击另一个框
-
查看我编辑的答案以实现您在上述评论中的要求 - 请注意,您需要删除 mouseout() 位,否则背景图像将不会“停留”
标签: javascript html css click mouseover