我要上coverImg鼠标悬停则显示coverInfo为什么盒子立即消失?
的coverInfo显示标题和图像
的描述则coverInfo确实显示
,但我想coverInfo留点击时鼠标自身
但它立即消失。
那么我错过了什么?
的HTML
<div class="workshop_img">
<div class="coverInfo"></div>
<a href="#">
<span class="coverImg" style="background-image:url('images/work/show1.jpg')" title="Chictopia "></span>
</a>
的CSS:
.coverInfo {
position:absolute;
width: 200px;
height:200px;
background:rgba(0,0,0,0.5);
top:30%;
left:30%;
display:none;
}
看到jQuery代码
$(function() {
$(".coverImg").each(function() {
//make the background image move a little pixels
$(this).css({
'backgroundPosition' : "-40px 0"
}).mouseover(function() {
$(this).stop().animate({
'backgroundPosition' : " -20px -60px "
}, {
duration : 90
});
//shwo the info box
var content = $(this).attr("title");
$("<div class='coverInfo'></div>").text(content).prependTo($(this).parent()).fadeIn("fast");
}).mouseout(function() {
$(this).stop().animate({
'backgroundPosition' : "-40px 0"
}, {
duration : 200,
});
$(this).parent().find(".coverInfo").stop().fadeOut("fast");
})
})
});
</div>
编辑:
我寻觅了很多,发现类似的东西,我把他们和下面给出共同解决我的问题的答案,这里是代码:
$(function() {
$(".coverImg").css({
'backgroundPosition' : "-40px 0"
}).mouseenter(function() {
var box = $(this).parents(".workshop_img").find(".coverInfo");
var content = $(this).attr("title");
var info = box.text(content);
$(this).stop().animate({
'backgroundPosition' : " -20px -60px "
},90);
info.show();
}).mouseleave(function() {
var box = $(this).parents(".workshop_img").find(".coverInfo");
var content = $(this).attr("title");
var info = box.text(content);
$(this).stop().animate({
'backgroundPosition' : "-40px 0"
},200);
info.stop().hide();
});
});
它刚刚干净,但不能正常工作。 什么问题?
我首先使用CSS来显示:无,这工作正常吗? – Lien 2012-01-27 06:50:59
@strangeline - 是的,它会隐藏起来。 – jfriend00 2012-01-27 06:56:45
看到编辑,我接受了建议并尝试了很多,但它仍然无法正常工作 – Lien 2012-01-27 08:30:58