jQuery悬停效果::
问题描述:
当我将鼠标悬停在div上时发射了几个效果。问题是div也有伪元素:: after,它使用内容CSS规则用虚拟元素(播放按钮)填充div。jQuery悬停效果::
当我悬停除了:: after元素所在空间以外的div的任何部分时,我的悬停效果就起作用。
简单地说,我想知道是否有方法使用jQuery指向:: after元素。我试图将:: after元素定义为一个名为“play”的变量,但是在那里也没有运气。这是我的脚本:
var play = $('a.image-wrap::after');
$(".image-holder, .big-headline a, .small-headline a, play").on({mouseenter: function() {
$('.image-holder').css('background-color', color);
$('.image-holder img').css({
'mix-blend-mode': 'multiply',
opacity: .6
});
if ($(window).width() > 1115) {
$('.read').css('right', '35%');
} else {
$('.read').css('right', '0');
}
},
mouseleave: function() {
$('.image-holder').css('background-color', '');
$('.image-holder img').css({
'mix-blend-mode': '',
opacity: ''
});
$('.read').css('right', '');
}
});
答
如果您只是将新的CSS添加到样式中,然后在完成悬停后将其删除,该怎么办?它工作得很好:
$(".example").on("mouseenter", function() {
\t $("#workAround").html(".example:after {background:pink}");
}).on("mouseleave", function() {
\t $("#workAround").html("");
});
.example {
\t height:10px;
\t width:100px;
\t background:green;
\t margin:20px 0 20px 0;
}
.example:after {
\t content:'';
\t background:red;
\t height:10px;
\t width:100%;
display: block;
\t position:relative;
\t bottom:-10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style id="workAround"></style>
<div class="example"></div>
更好地处理它在CSS没有jQuery的 – user7417866
您不能访问::后,使用:: JS之前。你应该使用CSS和变换 –
为什么不向父元素添加一个类,那么你可以定位:例如'.hovering:hover:after' – Pete