简体   繁体   English

在悬停时显示隐藏的div

[英]Show hidden div on hover

I have a hidden div with a buttin that I would like to appear when you hover over the div 'person-wrap'. 我有一个带有Buttin的隐藏div,当您将鼠标悬停在div“ person-wrap”上时,我想显示它。 How can I do this? 我怎样才能做到这一点? Should I use CSS tricks or can it be done with JQUERY? 我应该使用CSS技巧还是可以使用JQUERY完成?

JSFIDDLE: http://jsfiddle.net/ceTdA/3/ JSFIDDLE: http : //jsfiddle.net/ceTdA/3/

The div I would like to have appear: 我希望出现的div:

#buttons {
display: none;
    position:absolute;
    right:10px;
    top:10px;
margin: 0px 0px 0px 0px;
height: 30px;
width: 225px;
overflow: auto;
 }

Given that your #buttons div is a child of #person-wrap you can do it with just CSS: 假设您的#buttons div是#person-wrap的子代,则可以只使用CSS来完成:

#person-wrap:hover #buttons {
    display : block;
}

Demo: http://jsfiddle.net/ceTdA/4/ 演示: http//jsfiddle.net/ceTdA/4/

You should try this code: 您应该尝试以下代码:

$("#person-wrap").hover(function() {
    $(this).find('#buttons').show();
}, function() {
    $(this).find('#buttons').hide();
});

nnnnnn explains a pure css way which is best, but it's pretty simple with jQuery as well, all it does is call the first function while the mouse is hovering and the second when the mouse leaves. nnnnnn解释了一种最佳的纯CSS方式,但是使用jQuery也非常简单,它所做的只是在鼠标悬停时调用第一个函数,而在鼠标离开时调用第二个函数。

$("#person-wrap").hover(
    function () {
        $("#buttons").addClass("hover");
},
    function () {
        $("#buttons").removeClass("hover");
});

And simple css: 和简单的CSS:

.hover{
    display:inline;
}

add this css: 添加此CSS:

#profile-pic:hover #buttons{
     display:inline;
} 

here is working jsfiddle 这是工作jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM