gpt4 book ai didi

html - Css 动画随机延迟

转载 作者:可可西里 更新时间:2023-11-01 13:03:27 26 4
gpt4 key购买 nike

我正在尝试为漫画工作室构建网页,我希望其中一个 Angular 色经常从侧面出现。到目前为止,我在 css 中有这个

        .charc {
animation:peek 20s infinite;
left:-500px
}

@-webkit-keyframes peek{
1% {transform:translateX(-500px)}
10%{transform:translateX(100px)}
20% {transform:translateX(-200px)}
100% {transform:translateX(-500px)}
}

和html

<img src="character.jpg" class="charc"/>

这意味着 Angular 色一遍又一遍地出现。我不知道是否可以在 CSS 中获取随机数字,但我想如果可以,你们就会知道

附注我知道这仅适用于 chrome,但我会尽快更改。

最佳答案

你需要为此使用 js/jQuery。

    function move() {
$('.charc')
.animate({
left: '-500px'
}, 200)
.animate({
left: '100px'
}, 400)
.animate({
left: '50px'
}, 400)
.animate({
left: '-500px'
}, 100, function() {
var nextIn = Math.floor(Math.random() * 1000);
setTimeout('move()', nextIn);
})
}

$(document).ready(function() {
move();
});
#scene {
width: 500px;
height: 100px;
border: 2px solid black;
margin: 20px;
}
.charc {
position: absolute;
left: -500px;
top: 20px;
width: 20px;
height: 20px;
background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="scene">
<div class="charc"></div>
</div>

关于html - Css 动画随机延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36220638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com