我想在有人将鼠标悬停在产品上时显示免费标签,但是当我设置免费标签时
visibility:hidden
它不起作用。当我删除它时,它可以正常显示所有产品,而不是单独悬停
$(function() {
$('.product').hover(function() {
if ($('.free_label').is(':hidden')) {
$('.free_label').hide();
} else {
$('.free_label').show();
}
return false;
});
});
https://jsfiddle.net/dptp6bj9/
我想在悬停时显示免费标签
答案 0 :(得分:1)
只需在悬停时设置 free_label
$(function() {
$('.product').hover(function() {
$(this).find('.free_label').css('visibility', 'visible');
}, function() {
$('.free_label').css('visibility', 'hidden');
});
});
.free_label {
color: #000;
font-size: 30px;
border: 1px solid #000;
visibility: hidden;
}
.planning_domain {
height: 300px;
width: 200px;
background-color: red;
cursor: pointer
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="product">product1
<div class="free_label">FREE!</div>
</div>
<div class="product">product2
<div class="free_label">FREE!</div>
</div>
<div class="product">product3
<div class="free_label">FREE!</div>
</div>
&#13;
x *(void**)0x600fe8
&#13;
我希望这会有所帮助!
答案 1 :(得分:0)
我对您的代码进行了一些更改,请查看https://jsfiddle.net/x1ae4jqk/
$(function() {
$('.product').hover(function() {
if ($('.free_label').hasClass('hidden')) {
$('.free_label').removeClass('hidden');
} else {
$('.free_label').addClass('hidden');
}
});
});