【发布时间】:2016-10-31 16:05:01
【问题描述】:
我在添加悬停类时遇到了一些问题。我已经掌握了它的基础知识,但我的最终结果并不是我想要的。
悬停在profile-pic-container 上时,我正在寻找profile-pic-hover 仅从profile-pic-container 底部升起30% 的高度。我也无法弄清楚如何设置 #profile-pic-change 以在此悬停时显示。
我做错了什么?
$('#profile-pic-container').hover(
function(){ $(this).addClass('profile-pic-hover') },
function(){ $(this).removeClass('profile-pic-hover') }
)
#profile-pic-container {
position: relative;
width: 200px;
height: 200px;
border: 1px solid black;
cursor: pointer;
}
.profile-pic-hover {
background: rgba(0, 0, 0, 0.5);
height: 30%;
width: 100%;
bottom: 0;
}
#profile-pic-change {
display: none;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="profile-pic-container">
<div id="profile-pic-change">Change picture</div>
</div>
【问题讨论】:
-
为什么要使用 JavaScript?
#profile-pic-container:hover {} -
profile-pic-hover和profile-pic-container也是同一个元素,所以...... 从 profile-pic-container 的底部开始,只出现 30% 的高度 .... 不会像您想象的那样使用您的实际 css 代码 -
那我该怎么做才能让它只上升 30%。
-
@DaniP 这太完美了!留下答案。
标签: javascript jquery html css hover