animation动画属性的使用

动画的属性分析及举例—用动画控制某物(比如小车)的移动

动画的相关属性

将动画属性简写之后,animation 后面的顺序:

animation-name,animation-duration, animation-timing-function,animation-delay,animation-iteration-count,animation-direction,animation-fill-mode , animation-play-state

animation-name

这个动画的名字

animation-duration

动画持续的时间

比如:1s

animation-timing-function

规定动画的速度曲线

比如:ease(可以为任意的贝塞尔曲线)

关于贝塞尔曲线:文章

animation-delay

规定动画何时开始

比如:1s

animation-iteration-count

规定动画被播放的次数

比如:1

animation-direction

指示动画是否反向播放

比如:normal、reverse

animation-fill-mode

规定动画是留在最后一帧还是退回到开始

比如:none、forward

animation-play-state

确定动画是否在播放

比如:running、paused

举例:用动画属性控制小车的移动

分析:主要会用到 animation-play-state 这个属性

具体的代码:

<template>
    <div class="content">
        <div class="car" :style="[Style]">
            <img src="https://picgo-use-images.oss-cn-shanghai.aliyuncs.com/images/ff68bc95-ee2c-483b-b676-7a29539bab10.svg" alt="">
        </div>

        <button @click="control()">{{instructions}}</button>
    </div>
</template>

<script>
export default {
    name: "App",

    data() {
        return {
            Style: {
                "animation-play-state": "paused",
            },

            instructions: "开始",
        };
    },

    methods: {
        control() {
            if (this.Style["animation-play-state"] == "paused") {
                this.Style["animation-play-state"] = "running";
                this.instructions = "暂停";
            } else {
                this.Style["animation-play-state"] = "paused";
                this.instructions = "开始";
            }
        },
    },
};
</script>

<style>
.content {
    width: 1000px;
    height: 1000px;
    background-color: gray;
}

.car {
    width: 50px;
    height: 50px;
    animation: go 10s ease 1s 1 normal none;
}

img {
    width: 100%;
    height: 100%;
}

button {
    display: block;
    width: 50px;
    height: 30px;
    margin: 0 auto;
    margin-top: 200px;
}

@keyframes go {
    0% {
        margin-left: 0px;
    }

    100% {
        margin-left: 900px;
    }
}
</style>

效果:

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

城南顾北

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值