CSS3 @keyframes动画
程序员文章站
2022-03-16 18:58:40
...
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#box {
width: 100px;
height: 100px;
background-color: pink;
position: relative;
/*animation: boxMove 5s infinite;*/
}
@keyframes boxMove {
from {
left: 0px;
}
to {
left: 300px;
}
}
</style>
</head>
<body>
<input type="button" value="开始" id="btn">
<div id="box"></div>
<script>
var btn = document.getElementById('btn');
var box = document.getElementById('box');
btn.onclick = function () {
// box的横坐标逐渐增大 缓慢向右移动
box.style.animation = 'boxMove 5s';
}
</script>
</body>
</html>
下一篇: css3 @keyframes 动画