gpt4 book ai didi

jquery - 使用 jQuery 添加类不显示效果

转载 作者:太空宇宙 更新时间:2023-11-03 21:45:56 24 4
gpt4 key购买 nike

我有一个 HTML 如下:

<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="span7">
<div class="home-image left-image">
<img class="photography-left-top" src="http://placehold.it/700x440" />
<p class="image-text_left">Wedditng Photography</p>
</div>

<h5>Heading</h5>
</div>
<div class="span5">
<div class="home-image right-image right-image-top">
<img class="photography-right-top" src="http://placehold.it/400x200" />
<p class="image-text_right-top">Fashion Photography</p>
</div>
<div class="home-image right-image right-image-bottom">
<img class="photography-right-bottom" src="http://placehold.it/400x200" />
<p class="image-text_right-bottom">Contact</p>
</div>

<h5>Heading</h5>
</div>

</div>

</div>

还有 CSS:

.home-image {
position:relative;
}
.photography-left-top,.photography-right-top,.photography-right-bottom {
position : absolute;
}
.image-text_left {
display:none;
position:absolute;
width:300px;
top:200px;;
left:200px;
z-index : 100;
font-weight:bold;
}
.image-text_right-top,.image-text_right-bottom {
display:none;
position:absolute;
width:300px;
top:100px;
left:100px;
z-index : 100;
font-weight:bold
}
.right-image-bottom {
margin-top:220px;
position:relative
}
.right-top {
position:relative
}
.home-img-hover {
background:#911717;
}

JS:

$(document).ready(function(){

$(".left-image").hover(function () {
$(this).find('.photography-left-top').fadeTo('slow',0);
$(this).addClass('home-img-hover');
$('.image-text_left').show();
},
function () {
$(this).find('.photography-left-top').fadeTo('400',1.0);
$('.image-text_left').hide();
});

因为 addClass('home-img-hover') 会将 a 类添加到当前 class 我期待在我将鼠标悬停在 left 上时出现背景颜色-图像。但它显示白色默认背景。为什么?

Sample in JSFiddle

最佳答案

它完全符合您的预期,您只是看不到它,因为 .home-image 没有高度,因为它里面的所有内容都是从普通文档中取出的流(使用 position:absolute)。尝试给 .home-image 一些尺寸,您就会明白我的意思:

.home-image {
position:relative;
width:400px;
height:240px;
}

JSFiddle

关于jquery - 使用 jQuery 添加类不显示效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20609503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com