javascript - jQuery 动画中的伪元素

标签 javascript jquery html css

点击 div width50% 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/

相关文章:

javascript - 处理时间长可能是由于 getValue 和单元格插入

javascript - 外部 javascript 文件在 IE 中不起作用

javascript - JavaScript中有onCreate这种事件吗?

php - javascript/jquery : get info for a remote image

javascript重定向无论如何都不起作用

javascript - JSON - 从 REST 调用中提取调用

javascript - 如何将无输入元素从html发送到python

jquery - 让 jquery 只运行一次

javascript - 编辑 tumblr 主题 html 以删除一些元素

javascript - 从图像拖放到另一个图像上