当前位置: 首页 > news >正文

Vue 实现的精彩动画效果

在 Vue 开发中,我们可以利用<transition>组件来打造各种令人惊艳的动画效果。下面来详细看看这些有趣的动画效果及其实现代码。

一、缩放类效果

  1. zoom-in(整体放大进入)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="zoom-in"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.zoom-in-enter-active {animation: zoomIn 0.5s ease;
}@keyframes zoomIn {from {transform: scale(0);}to {transform: scale(1);}
}
</style>
  1. zoom-in-left(从左侧放大进入)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="zoom-in-left"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.zoom-in-left-enter-active {animation: zoomInLeft 0.5s ease;
}@keyframes zoomInLeft {from {transform: scale(0) translateX(-100%);}to {transform: scale(1) translateX(0);}
}
</style>
  1. zoom-in-right(从右侧放大进入)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="zoom-in-right"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.zoom-in-right-enter-active {animation: zoomInRight 0.5s ease;
}@keyframes zoomInRight {from {transform: scale(0) translateX(100%);}to {transform: scale(1) translateX(0);}
}
</style>
  1. zoom-in-top(从顶部放大进入)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="zoom-in-top"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.zoom-in-top-enter-active {animation: zoomInTop 0.5s ease;
}@keyframes zoomInTop {from {transform: scale(0) translateY(-100%);}to {transform: scale(1) translateY(0);}
}
</style>
  1. zoom-in-bottom(从底部放大进入)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="zoom-in-bottom"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.zoom-in-bottom-enter-active {animation: zoomInBottom 0.5s ease;
}@keyframes zoomInBottom {from {transform: scale(0) translateY(100%);}to {transform: scale(1) translateY(0);}
}
</style>
  1. zoom-in-center-x(沿水平中心轴放大进入)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="zoom-in-center-x"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.zoom-in-center-x-enter-active {animation: zoomInCenterX 0.5s ease;
}@keyframes zoomInCenterX {from {transform: scaleX(0);}to {transform: scaleX(1);}
}
</style>
  1. zoom-in-center-y(沿垂直中心轴放大进入)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="zoom-in-center-y"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.zoom-in-center-y-enter-active {animation: zoomInCenterY 0.5s ease;
}@keyframes zoomInCenterY {from {transform: scaleY(0);}to {transform: scaleY(1);}
}
</style>

二、滑动类效果

  1. slide(普通滑动)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="slide"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.slide-enter-active {animation: slideIn 0.5s ease;
}@keyframes slideIn {from {transform: translateX(-100%);}to {transform: translateX(0);}
}
</style>
  1. slide-left(向左滑动)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="slide-left"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {name: 'Test',data() {return {isShow: true,};},
};
</script><style scoped>
.slide-left-enter-active {animation: slideLeftIn 0.5s ease;
}@keyframes slideLeftIn {from {transform: translateX(100%);}to {transform: translateX(0);}
}
</style>
  1. 向右滑动(slide-right)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="slide-right"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {data() {return {isShow: false};}
};
</script><style scoped>
.slide-right-enter-active,
.slide-right-leave-active {transition: all 0.5s ease;
}.slide-right-enter,
.slide-right-leave-to {transform: translateX(-100%);
}
</style>
  1. 向上滑动(slide-top)
<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="slide-top"><h1 v-show="isShow">你好啊</h1></transition></div>
</template><script>
export default {data() {return {isShow: false};}
};
</script><style scoped>.slide-top-enter-active,.slide-top-leave-active {transition: all 0.5s ease;}.slide-top-enter,.slide-top-leave-to {transform: translateY(-100%);}
</style>
  1. 向下滑动(slide-bottom)
<template><div class="slide-bottom-animation" v-if="showBottom">向下滑动示例</div>
</template><script>
export default {data() {return {showBottom: false};}
};
</script><style scoped>.slide-bottom-enter-active,.slide-bottom-leave-active {transition: all 0.5s ease;}.slide-bottom-enter,.slide-bottom-leave-to {transform: translateY(100%);}</style>

三、淡入淡出效果

<template><div><button @click="isShow =! isShow">显示/隐藏</button><transition name="fade-animation"><h1 v-show="isShow">你好啊</h1></transition></div> 
</template><script>
export default {data() {return {isShow: true};}
};
</script><style scoped>
.fade-animation-enter-active,
.fade-animation-leave-active {transition: opacity 0.5s ease;
}.fade-animation-enter,
.fade-animation-leave-to {opacity: 0;
}
</style>
http://www.lryc.cn/news/364182.html

相关文章:

  • JVM类加载机制详解(JDK源码级别)
  • 美国年轻人热衷床上“摆烂”,沃尔玛发掘床上用品新商机!
  • 3168. 候诊室中的最少椅子数
  • C# PaddleOCR 单字识别效果
  • pyopengl 立方体 正投影,透视投影
  • 人工智能任务5-高级算法工程师需要学习哪些课程与掌握哪些能力
  • 服务器上创建搭建gitlab
  • LangChain学习之prompt格式化与解析器使用
  • 基于EasyX的贪吃蛇小游戏 - C语言
  • 使用Docker辅助图像识别程序开发:在Docker中显示GUI、访问GPU、USB相机以及网络
  • Java中常见错误-泛型擦除及桥接方法问题及解决方案
  • Linux 程序守护脚本
  • 跨境电商|Facebook Marketplace怎么做?
  • .gitignore 文件
  • qt中实现多语言功能
  • 数据结构与算法之 leetcode 513. 找树左下角的值 (BFS) 广度优先
  • mysql中的函数
  • Shell正则表达式与文本处理器
  • 双指针法 ( 三数之和 )
  • 感染恶意代码之后怎么办?
  • 【计算机网络】P3 计算机网络协议、接口、服务的概念、区别以及计算机网络提供的三种服务方式
  • 多角度剖析事务和事件的区别
  • 模糊小波神经网络(MATLAB 2018)
  • HTML布局
  • 数据结构:双链表
  • Python3 元组、列表、字典、集合小结
  • 2024会声会影破解免费序列号,激活全新体验!
  • 机器学习18个核心算法模型
  • 平滑值(pinghua)
  • 使用matplotlib绘制折线条形复合图