我要上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