Vue animation notes在Vue中实现动画主要有以下几种方式:
**一、基于Vue过渡类名实现动画**
1. **过渡类名及含义**
- 进入过程:
- `v - enter`:进入的起始时刻(例如`Opacity:0`),表示进入之前元素的状态,此时还没有进入。
- `v - enter - active`:进入的过程(时间段),即入场动画时间段。
- `v - enter - to`:进入后的时刻(例如`Opacity:1`)。
- 离开过程:
- `v - leave`:离开的起始时刻(例如`Opacity:1`)。
- `v - leave - active`:离开的过程(时间段),即出场动画时间段。
- `v - leave - to`:离开后的时刻(例如`Opacity:0`),动画离开之后,到达离开的终止状态,此时元素的动画已经结束。
2. **实现步骤**
- 使用`transition`元素,把需要被动画控制的元素包裹起来。
- 自定义两组样式,控制`transition`内部元素实现动画。例如:
```css
.v - enter,.v - leave - to{
opacity: 0;
transform:translateX(90px);
}
.v - enter - active,.v - leave - active{
transition: all 1s ease;
}
```
**二、自定义类名实现动画**
1. 修改`transition`标签的`name`属性为自定义名称,同时修改属性类中的`v`为刚刚的自定义名称。例如将`v - enter`修改为`my - enter`。假设定义了`my`这个自定义名称,样式可以这样写:
```css
.my - enter,.my - leave - to{
opacity: 0;
transform:translateY(90px);
}
.my - enter - active,.my - leave - active{
transition: all 1s ease;
}
```
**三、使用第三方类库animate.css实现动画**
1. 入场使用`bounceIn`,离场使用`bounceOut`。
2. 标签`transition`绑定动画需要加`animated`。有两种写法:
- 一种是在`transition`标签中添加`enter - active - class`和`leave - active - class`属性:
```html
<link rel="stylesheet" href="./animate.min.css">
<div class = "app ">
<input type="button" name="" value="转换" v - on:click="flag =!flag">
<transition enter - active - class="animated bounceIn" leave - active - class="animated bounceOut">
<h3 v - if="flag">加了动画的h3标签</h3>
</transition>
</div>
```
- 或者将动画写到元素里面:
```html
<transition enter - active - class=" bounceIn" leave - active - class=" bounceOut">
<h3 v - if="flag" class="animated">加了动画的h3标签</h3>
</transition>
```
**四、在路由动画中的应用**
1. 在想要跳转的路由外面加一层`<transition>`标签,例如`<transition name = "slide"><RouterView></RouterView></transition>`。
2. 也可以在`<router - view>`中使用`v - slot`来定义过渡效果,如:
```html
<router - view v - slot = "{ Component }">
<transition name = "bounce" mode = "out - in">
<component :is = "Component" />
</transition>
</router - view>
<router - view v - slot = "{ Component }">
<transition name = "fade" mode = "out - in">
<component :is = "Component" />
</transition>
</router - view>
```
3. 在`style`中定义相应的过渡样式,例如对于`fade`样式:
```css
.fade - enter - active {
transition: all 0.3s ease - out;
}
.fade - leave - active {
transition: all 0.3s cubic - bezier(1, 0.5, 0.8, 1);
}
.fade - enter - from,.fade - leave - to {
transform: translateX(20px);
opacity: 0;
}
```
对于`bounce`样式:
```css
.bounce - enter - active {
animation: bounce - in 0.5s;
}
.bounce - leave - active {
animation: bounce - in 0.5s reverse;
}
@keyframes bounce - in {
0% {
transform: scale(0);
}
50% {
transform: scale(1.25);
}
100% {
transform: scale(1);
}
}
```
其中`name`的作用是定义`style`的开头名称,默认是`v`开头,例如`v - enter - active`可以替换成`fade - enter - active`等。
<a href="/?from=ask_words" style="color:red" target="_blank">点击前往免费阅读更多精彩小说</a>
Vue animation effect summary在Vue中实现动画效果主要有以下几种方式:
**一、使用CSS动画**
1. **定义关键帧**
- 在组件的`<style>`部分定义CSS动画关键帧。例如,对于不同方向的滑动动画可以定义如下关键帧:
- 向左滑动进入:
```css
@keyframes slideInLeft {
from {
transform: translateX(-100%);
}
to {
transform: translateX(0);
}
}
```
- 向左滑动离开:
```css
@keyframes slideOutLeft {
from {
transform: translateX(0);
}
to {
transform: translateX(-100%);
}
}
```
- 向右、向上、向下滑动的进入和离开动画关键帧定义类似,只是在`translateX`和`translateY`的值上有所不同。
2. **创建动画类并应用**
- 定义好关键帧后,创建相应的动画类并应用到元素上。例如创建一个向左滑动进入的类:
```css
.slide - in - left {
animation: slideInLeft 0.5s forwards;
}
```
- 在Vue模板中,根据组件的数据属性来动态添加动画类到元素上。
**二、使用Vue的过渡系统**
1. **transition组件**
- **基本用法**
- transition组件是Vue提供的一个过渡组件,它包裹在要过渡的元素外面,并使用`name`属性指定过渡的名称。例如:
```html
<transition name = "fade"><p v - if = "show">Hello, Vue!</p></transition>
```
- **相关CSS类定义**
- 对于名为`fade`的过渡,需要在CSS中定义以下类:
- `.fade - enter - active`和`.fade - leave - active`:这两个类分别对应着元素插入和删除时的过渡效果。例如:
```css
.fade - enter - active,.fade - leave - active{
transition: opacity 0.5s;
}
```
- `.fade - enter`和`.fade - leave - to`:这两个类分别对应着元素插入和删除时的起始和结束状态。例如:
```css
.fade - enter,.fade - leave - to{
opacity:0;
}
```
2. **animation组件(用于更复杂动画效果)**
- **基本用法**
- 需要使用`keyframes`属性来指定动画的关键帧。例如:
```html
<animation :keyframes = "keyframes"><p v - if = "show">Hello, Vue!</p></animation>
```
- **关键帧定义**
- 在JavaScript中定义动画效果的关键帧。例如:
```javascript
data(){
return{
keyframes:([{opacity:0,transform:'translateY(-100%)'},{opacity:1,transform:'translateY(0)'}])
}
}
```
此外,当插入或删除包含在`transition`组件中的元素时,Vue会自动嗅探目标元素是否应用了CSS过渡或动画,如果是,在恰当的时机添加/删除CSS类名;如果过渡组件提供了JavaScript钩子函数,这些钩子函数将在恰当的时机被调用;如果没有找到JavaScript钩子并且也没有检测到CSS过渡/动画,DOM操作 (插入/删除) 在下一帧中立即执行。在元素的进入/离开过渡中,会有像`v - enter`(定义进入过渡的开始状态,在元素被插入之前生效,在元素被插入之后的下一帧移除)、`v - enter - active`(定义进入过渡生效时的状态,在整个进入过渡的阶段中应用,在元素被插入之前生效,在过渡/动画完成之后移除)等6个`class`切换。
<a href="/?from=ask_words" style="color:red" target="_blank">点击前往免费阅读更多精彩小说</a>
The main character is Rie.I recommend a few super interesting novels. " Painting a Silk Dress " was a modern romance novel written by Li Huashou. The female protagonist had a wolf in front of her and a tiger behind her, and she accidentally went to a brothel. However, she put aside her past and loved money. She also sought a dedicated husband and shouted for equality between men and women and monogamy. There was also a super beautiful cover.
'The Great Country's World Cup' was a sports and football article written by Wu Guanzhi. Reporter Zeng Zheng had transmigrated to a parallel world and was chosen as a scapegoat. He relied on the World Cup system to make a name for himself in the national football team. Although the superpowers were not outstanding, the plot was great. It was either brainless or the ending was rushed. Now that there was hope for the national football team, this novel about the national football team was worth reading.
The Great Onmyoji Summoning System was a sci-fi novel written by Aren't I White? The male lead, Chen Mo, was good-looking and had a group of supporting characters. The story was original and could be understood even if one had not played the Onmyoji game.
" The Path of the Space Boss " was a science fiction interstellar civilization novel written by a four-barreled cannon. The male protagonist transmigrated into an NPC, farmed, upgraded technology, and communicated with alien civilizations. The real Zerg setting was super cool.
I'm the best variety director, an urban novel written by Cheng1229. The TV producer's counterattack story after transmigrating to hell was also very exciting.
<a href="/?from=ask_words" style="color:red" target="_blank">Read more exciting novels for free</a>
What is a True Vue Picture Story?A True Vue Picture Story is basically a way of telling a tale through pictures. These pictures are often of great quality and are sequenced in a manner that makes the story easy to understand and enjoy. It can be about anything from adventures to personal experiences.
Vue downloads txts via the urlsOne way to download a txt-file through a Url-based file in the Vue is as follows: After the back-end returns the txt-file path, the front-end requests the path again. During the request process, the returned text format is set to `blob`, and then the download is based on `blob` and the coding format is set. The sample code is as follows:
```javascript
//Suppose this. Filerul is the ttp address of the txtfile, such as: 192.168.1.1:80//export/log.txt
this.$ axios.get(this.FileUrl, {
responseType: 'blob'//Get file stream
}).then((response) => {
//Create a Blob object with text content
const blob = new Blob((response.data), { type: 'application/;charset=utf-8' })
//create a temporary a tag for download
const a = document.createElement('a')
a.href = URL.createObjectURL(blob)
a.download = fileName
//add a tag to the document, trigger the click event, and then remove the a tag
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
})
```
There is another simple way. If it is in the `vue` page, you can put the txt template file in `static` and then write `<a href="/static/matchData.txt" download="文件模板.txt">file template</a>` in the `vue` page.(Note: The value of the `download` attribute is the download file name.txt.)
<a href="/?from=ask_words" style="color:red" target="_blank">Read more exciting novels for free</a>
This is the novel reader I made with vueIt was very powerful. If he wanted to make it more perfect, he could refer to the functions and designs of some existing excellent readers. For example, some readers supported multiple format (such as EPUB format), while others had good cross-platform compatibility and could be customized (such as changing the font, background color, etc.). If it was related to bookshelf management, he could learn from the functions of novel bookshelf classification query, book list query, ranking search, novel details view, novel source change, reading history record, and so on. In terms of page flipping effect, it could be a simple horizontal page sliding, or it could add animation effects according to needs (such as setting transitionDuration to increase animation).
<a href="/?from=ask_words" style="color:red" target="_blank">Read more exciting novels for free</a>