点击 div width 到 50% with animate 后,我用 pseudo 添加了一个圆圈,但是当动画播放时它隐藏了。我还尝试在 div 中使用 span 而不是伪元素,但没有成功。有什么想法吗?
$('a').click(function() {
$('div').animate({
width: 50 + "%"
}, 2000);
});
div {
width: 0%;
height: 2px;
background: red;
position: relative;
}
div span {
content: "";
position: absolute;
right: 0;
top: -2px;
width: 10px;
height: 10px;
background: red;
border-radius: 50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span></span>
</div>
<a>click</a>
我不想在播放动画时隐藏圆圈。
最佳答案
您可以为 div
使用 overflow: initial !important;
$('a').click(function(){
$('div').animate({
width: 50 + "%"
}, 2000);
});
div {
width: 0%;
height: 2px;
background: red;
position: relative;
overflow: initial !important;
}
div span {
display:inline-block;
content: "";
position: absolute;
right: 0;
top: -2px;
width: 10px;
height: 10px;
background: red;
border-radius: 50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span></span>
</div>
<a>click</a>
关于javascript - jQuery 动画中的伪元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41058461/