transtion-group过渡列表,移动过渡列表,状态过渡

1、过渡列表

<template>
	<div class="home_main">
		<button @click="increaseFun">增加</button>
		<button @click="reduceFun">减少</button>
		<div class="content">
			<transition-group leave-active-class="animate__animated animate__hinge"
				enter-active-class="animate__animated animate__jackInTheBox">
				<div class="box" v-for="(item, index) in dataList" :key="index">
					{{ item }}
				</div>
			</transition-group>
		</div>

	</div>
</template>

<script lang="ts" setup>
import Login from "../../components/login.vue"
import { ref, reactive } from "vue"
import 'animate.css';
const dataList = reactive<number[]>([1, 2, 3, 4, 5, 6])
const increaseFun = () => {
	dataList.push(dataList.length + 1)
}
const reduceFun = () => {
	dataList.pop()
}
</script>

<style lang="scss">
.home_main {
	width: 100%;
	height: 100vh;
	background: green;
	font-size: 18px;

	.content {
		display: flex;
		flex-wrap: wrap;
		word-break: break-all;
		box-sizing: border-box;
		padding: 10px 0;
		border: 1px solid red;

		.box {
			font-size: 40px;
			margin: 10px;
		}
	}

	.ap_from {
		width: 0;
		height: 0;
		transform: rotate(360deg);
	}

	.ap_active {
		transition: all 1.5s ease;
	}

	.ap_to {
		width: 200px;
		height: 200px;
	}

	.el-from {
		width: 0;
		height: 0;
		transform: rotate(360deg);
	}

	.fade-enter-active {
		transition: all 1.5s ease;
	}

	.fade-enter-to {
		width: 200px;
		height: 200px;
	}

	.el-from {
		width: 200px;
		height: 200px;
		transform: rotate(-360deg);
	}

	.fade-leave-active {
		transition: all 5s ease;
	}

	.fade-leave-to {
		width: 0;
		height: 0;
	}
}
</style>

2、列表的移动过渡

npm install lodash -S
npm install @types/lodash -D   
<template>
	<div class="home_main">
		<button @click="randomFun">随机</button>
		<transition-group move-class="move_info" tag="div" class="content">
			<div class="box" v-for="item in dataList" :key="item.id">
				{{ item.index }}
			</div>
		</transition-group>
	</div>
</template>

<script lang="ts" setup>
import { ref, reactive } from "vue"
import _ from 'lodash'
import 'animate.css';
const dataList = ref(Array.apply(null, { length: 81 } as number[]).map((_, index) => {
	return {
		id: index,
		index: (index % 9) + 1
	}
}))
console.log(dataList)
const randomFun = () => {
	dataList.value = _.shuffle(dataList.value)
}
</script>

<style lang="scss">
.home_main {
	width: 100%;
	height: 100vh;
	background: green;
	font-size: 18px;

	.move_info {
		transition: all 1s;
	}

	.content {
		display: flex;
		flex-wrap: wrap;
		text-align: center;
		width: calc(50px * 10 + 9px);
		box-sizing: border-box;
		padding: 10px 19px;
		border: 1px solid red;
		margin: 30px auto;
		box-sizing: border-box;

		.box {
			font-size: 50px;
			height: 50px;
			width: 50px;
			border: 1px solid #ddd;
		}
	}

	.ap_from {
		width: 0;
		height: 0;
		transform: rotate(360deg);
	}

	.ap_active {
		transition: all 1.5s ease;
	}

	.ap_to {
		width: 200px;
		height: 200px;
	}

	.el-from {
		width: 0;
		height: 0;
		transform: rotate(360deg);
	}

	.fade-enter-active {
		transition: all 1.5s ease;
	}

	.fade-enter-to {
		width: 200px;
		height: 200px;
	}

	.el-from {
		width: 200px;
		height: 200px;
		transform: rotate(-360deg);
	}

	.fade-leave-active {
		transition: all 5s ease;
	}

	.fade-leave-to {
		width: 0;
		height: 0;
	}
}
</style>

在这里插入图片描述
在这里插入图片描述

3、状态过渡

<template>
    <div class="transtion_main">
        <input v-model="inputNum.currentValue" step="20" type="number">
        {{ inputNum.changeNumber.toFixed(0) }}
    </div>
</template>

<script lang='ts' setup>
import { reactive, ref, watch } from 'vue'
import gsap from "gsap"

const inputNum = reactive({
    currentValue: 0,
    changeNumber: 0
})
watch(() => inputNum.currentValue, (newValue, oldValue) => {
    gsap.to(inputNum, {
        duration: 10,
        changeNumber: newValue
    })
})
</script>

<style scoped lang="scss">
.transtion_main {
    font-size: 50px;

    input {
        height: 70px;
        width: 300px;
        display: block;
        font-size: 50px;
    }
}
</style>

在这里插入图片描述
也就是数字在一直变化累加到20000的这样一个过渡效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会为您解答关于html中transition属性和CSS3中Transition动画属性的用法。 在HTML中,transition属性表示元素在一定时间内从一种样式转换为另一种样式的过程。transition属性需要指定以下几个参数: - transition-property:指定过渡的CSS属性,可以使用all来表示所有属性都过渡。 - transition-duration:指定过渡的时间,以秒或毫秒为单位。 - transition-timing-function:指定过渡的时间函数,可以使用一些预定义的函数,如linear、ease、ease-in、ease-out等。 - transition-delay:指定过渡的延迟时间,以秒或毫秒为单位。 举个例子,如果您想让一个元素在鼠标悬停时变成红色,可以这样写: ``` div { background-color: blue; transition-property: background-color; transition-duration: 1s; transition-timing-function: ease-in-out; } div:hover { background-color: red; } ``` 这样,在鼠标悬停时,该元素的背景色会从蓝色平滑地过渡到红色。 在CSS3中,Transition动画属性是与transition属性相关的一组属性,包括以下几个参数: - transition-property:同HTML中的transition-property参数。 - transition-duration:同HTML中的transition-duration参数。 - transition-timing-function:同HTML中的transition-timing-function参数。 - transition-delay:同HTML中的transition-delay参数。 - transition: 简写形式,可以一次性指定以上所有参数。例如:transition: background-color 1s ease-in-out 0s。 此外,CSS3中还新增了一些过渡效果,包括旋转、缩放、平移等。举个例子,如果您想让一个元素在鼠标悬停时旋转180度并缩小一半,可以这样写: ``` div { width: 100px; height: 100px; background-color: blue; transition: transform 1s ease-in-out; } div:hover { transform: rotate(180deg) scale(0.5); } ``` 这样,在鼠标悬停时,该元素会以一个180度的旋转和50%的缩放平滑地过渡到新的状态。 希望这些内容能够帮到您,如果您还有其他问题,请随时提出。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值