How does vue achieve animation effects? The following article will give you a brief understanding of transitions and animations encapsulated in Vue. I hope it will be helpful to you!
Vue encapsulated transition and animation
1. Function
When inserting, updating, or removing DOM elements, add style class names to the elements when appropriate.
2. Writing method
Prepare the style: the style of the element entry
<template> <div> <button @click="isShow = !isShow">隐藏展示</button> <transition name="hidden" appear> <h1 id="隐藏展示">隐藏展示</h1> </transition> </div> </template> <script> export default { name: "Test", data() { return { isShow: true }; } }; </script> <style scoped> h1 { background-color: orange; } .hidden-enter-active { animation: shanyu 1s; } .hidden-leave-active { animation: shanyu 1s reverse; } @keyframes shanyu { from { transform: translateX(-100%); } to { transform: translateX(0px); } } </style>
[Related recommendations: vuejs Video tutorial、web front-end development】
3. Style
You need to have this animate.css first Oh
npm i animate.css
1.v-enter: the starting point of entry
2.v-enter-active: in the process of entry
3 .v-enter-to: End point of entry
<template> <div> <button @click="isShow = !isShow">隐藏展示</button> <transition-group name="shanyu" appear> <h1 id="隐藏展示">隐藏展示</h1> <h1 id="隐藏展示">隐藏展示</h1> </transition-group> </div> </template> <script> export default { name: "Test2", data() { return { isShow: true }; } }; </script> <style scoped> h1 { background-color: rgb(139, 37, 255); } /* 进入的起点,离开的起点 */ .shanyu-enter, .shanyu-leave-to { transform: translateX(-100%); } .shanyu-enter-active,.shanyu-leave-active{ transition: .5s linear; } /* 进入的终点离开的终点 */ .shanyu-enter-to, .shanyu-leave { transform: translateX(0); } </style>
Style of element leaving:
1.V-leave: Starting point of departure
2.V-leave-active : During the process of leaving
3.V-leave-to: The end point of leaving
4. Use
<transitionname="hello"> <h1 id="你好啊-nbsp">你好啊! </h1> </transition>
Note: If there are multiple elements that need to be transitioned, you need to use:
<transition-group name="shanyu" appear> <h1 id="隐藏展示">隐藏展示</h1> <h1 id="隐藏展示">隐藏展示</h1> </transition-group>
(Learning video sharing: vuejs introductory tutorial, Basic programming video)
The above is the detailed content of A brief analysis of how vue achieves animation effects. For more information, please follow other related articles on the PHP Chinese website!

vue中props可以传递函数;vue中可以将字符串、数组、数字和对象作为props传递,props主要用于组件的传值,目的为了接收外面传过来的数据,语法为“export default {methods: {myFunction() {// ...}}};”。

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
