我有一个CSS动画和我的js代码,做一些事情,让说遍历我:CSS动画忙
for (var i = 0; i < 10000; i++) {
console.log(i);
}
此代码运行握住我的动画。 有没有解决方案?如果不使用GIF
HTML + CSS代码
<div class="progress">
<span></span>
</div>
.progress {
width: 500px;
max-width: 500px;
height: 50px;
overflow: hidden;
> span {
display: block;
position: relative;
height: 100%;
width: 200%;
transform: translateX(-50%);
overflow: hidden;
background-color: #4a4a4a;
&:after, >span {
content: "";
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background-image: linear-gradient(
-45deg,
rgba(#fff, .2) 25%,
transparent 25%,
transparent 50%,
rgba(#fff, .2) 50%,
rgba(#fff, .2) 75%,
transparent 75%,
transparent
);
z-index: 1;
background-size: 30px 30px;
overflow: hidden;
-webkit-animation: move 4s linear infinite;
-moz-animation: move 4s linear infinite;
animation: move 4s linear infinite;
}
}
}
@keyframes move {
0% {
transform: translateX(0%);
}
100% {
transform: translateX(50%);
}
}
为什么你需要使用'console.log(i);'? – currarpickt
动画运行良好没有看到任何暂停或迟到开始 – krish
如果您的JS需要很长时间才能执行,您应该考虑将其分成较小的位,以避免您的页面对用户交互无响应。 – gcampbell