前端vue transition过渡动画

首先新建一个基于uni-app框架为transition.vue的测试文件,在其中编写如下JavaScript、HTML和CSS代码:

<template><view class="content"><div id="Application"><div :class="cls" @click="run"></div></div></view></template>

<script>export default {data() {return {

cls: "demo"}},onLoad() {

},methods: {run() {if (this.cls == "demo") {this.cls = "demo-ani"} else {this.cls = "demo"}}}}</script>

<style>.content {display: flex;flex-direction: column;align-items: center;justify-content: center;}

/* .demo {width: 100px;height: 100px;background-color: red;} */

.demo {width: 100px;height: 100px;background-color: red;transition-property: width, height, background-color;transition-duration: 2s;transition-timing-function: linear;transition-delay: 1s;}

.demo-ani {width: 200px;height: 200px;background-color: blue;transition: width 2s, height 2s, background-color 2s;}</style>

如以上代码所示,CSS中定义的demo-ani类中指定了transition属性,这个属性中可以设置要过渡的属性以及动画时间。运行上面的代码,单击页面中的色块,可以看到色块变大的过程会附带动画效果,颜色变化的过程也附带动画效果。上面的示例代码实际上使用了简写方式,我们也可以逐条属性对动画效果进行设置。

其中,transition-property用来设置动画的属性;transition-duration用来设置动画的执行时长;transition-timing-function用来设置动画的执行方式,linear表示以线性的方式执行;transition-delay用来进行延时设置,即延时多长时间后开始执行动画。

阅读全文下载完整组件代码请关注微信公众号: 前端组件开发

在这里插入图片描述

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

前端组件开发

你的钟意将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值