写一段微信可以打开的动效代码
时间: 2023-01-31 15:57:00 浏览: 73
你可以使用如下的代码来实现微信中的动画效果:
```
<html>
<head>
<style>
.box {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation: move 2s linear infinite;
}
@keyframes move {
0% {
left: 0;
}
100% {
left: 300px;
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
```
在这段代码中,我们使用了一个名为 "move" 的动画,它会让一个名为 "box" 的 div 元素从屏幕的左侧移动到右侧。这个动画的时长为 2 秒,动画的速度是匀速的,并且会无限循环播放。
你也可以使用 JavaScript 来控制动画的播放,例如在点击按钮时开始或停止动画。这里是一个例子:
```
<html>
<head>
<style>
.box {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation: move 2s linear infinite;
}
@keyframes move {
0% {
left: 0;
}
100% {
left: 300px;
}
}
</style>
</head>
<body>
<div class="box"></div>
<button onclick="startAnimation()">开始动画</button>
<button onclick="stopAnimation()">停止动画</button>
<script>
function startAnimation() {
var box = document.querySelector('.box');
box.style.animationPlayState = 'running';
}
function stopAnimation() {
var box = document.querySelector('.box');
box.style.animationPlayState = 'paused';
}
</script>
</body>
</html>
```
在这段代码中,我们添加了两个按钮,分别用来开始和停止动画。使用 JavaScript 的 `