我正在尝试找出如何编辑这段jQuery代码,以便只有悬停的父级显示其子级。目前,当任何父级被悬停时,所有子级都会显示。
非常感谢您的帮助。 jsFiddle
非常感谢您的帮助。 jsFiddle
jQuery(document).ready(function($) {
$(".parent").hover(
function () {
$(".child").addClass("hover");
},
function () {
$(".child").removeClass("hover");
}
);
});
.parent {
position:relative;
width:100px;
height:100px;
background:red;
display:inline-block;
float:left;
margin-right:6px;
}
.child {
width:inherit;
height:30px;
position:absolute;
bottom:0;
background-color:blue;
opacity:0;
transition:0.5s;
}
.child.hover {
opacity:1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent">
<div class="child">
</div>
</div>
<div class="parent">
<div class="child">
</div>
</div>
<div class="parent">
<div class="child">
</div>
</div>
this
时,事件的用途是什么?请解释一下。 - Shiladitya