Javascript 在悬停时删除:before属性
我的图像上有一个类,通过Javascript 在悬停时删除:before属性,javascript,jquery,css,Javascript,Jquery,Css,我的图像上有一个类,通过.images:before在其上放置一个覆盖。 现在我想(以jquery为例),删除悬停时的覆盖 以下是我的想法,但不起作用: $(document).ready(function(){ $('.images').hover(function (){ $(this).css('background',''); }); }); 这是css .image { position: relative; disp
.images:before
在其上放置一个覆盖。
现在我想(以jquery为例),删除悬停时的覆盖
以下是我的想法,但不起作用:
$(document).ready(function(){
$('.images').hover(function (){
$(this).css('background','');
});
});
这是css
.image {
position: relative;
display: inline-block;
}
.image:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: url('images/overlay.png');
}
非常感谢您的帮助您可以将伪选择器与伪元素结合使用:
.image {
position: relative;
display: inline-block;
}
.image:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: url('images/overlay.png');
}
.image:hover:before {
display : none;
}
Fiddle:您可以将伪选择器与伪元素组合:
.image {
position: relative;
display: inline-block;
}
.image:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: url('images/overlay.png');
}
.image:hover:before {
display : none;
}
Fiddle:您可以修改样式表规则,但最好的选择是避免使用伪元素。伪元素在与javascript交互时有奇怪的行为。您可以修改样式表规则,但最好的选择是避免使用该伪元素。伪元素在与javascript交互时有奇怪的行为。