|
|

楼主 |
发表于 2023-2-10 13:49
|
显示全部楼层
二楼代码:
- <style>
- #mybox {
- position: relative;
- left: 20px;
- width: 100px;
- height: 100px;
- background: pink;
- cursor: pointer;
- }
- @keyframes move {
- 0% { left: 20px; background: olive; }
- 20% { left: 300px; background: red; }
- 40% { left: 0px; background: green; }
- 80% { left: 600px; background: purple; }
- 100% { left: 450px; background: darkred; }
- }
- </style>
- <div id="mybox"></div>
- <script>
- mybox.onclick = () => {
- mybox.style.setProperty('animation','move 4s forwards');
- setTimeout(() => {
- mybox.style.setProperty('animation','');
- },7000);
- }
- </script>
复制代码 代码中,animation 动画没有放在CSS里绑定,写在了JS里,这是为了方便再帖子中观察。如果在本地测试,无需使用JS,代码可以改为下楼的样子。
|
评分
-
查看全部评分
|