New in Vue: Transition Effects

admin

Today I will continue to introduce you to a completely new feature of Vue, which is Transition Effects . It can be said that this is also one of the features of this framework.

Normally if you want to add effects (animate, delay, etc.) to actions on the DOM elements (for example, add items or remove) to make this action more professional, do for web applications to run more smoothly. What is the thing that every developer needs to do?

1. Using CSS with familiar animation attributes, web-kit-transaction:

and then add more items to create effects.

2. Use Jquery methods that support 1 animate number:

The above are some ways that every dev has been using, and the above still have its own advantages, which will be more convenient for each user case.

However, instead of having to do the above steps, why don’t we integrate it into elements with such corresponding attributes.

That would be more convenient, and Vue implemented the Transition Effects feature based on those ideas.

Overview

As mentioned above, Vue provides us with the most convenient way to apply transition effects when existing conditions exist, such as adding, editing, and deleting items on the DOM. This feature includes:

+, Automatically apply CSS classes transition and effects .

+, Interacting with the 3rd-party CSS animate libraries (Animate.css, etc.)

+, Use javascript to manipulate the DOM during the transition.

+, Interact with the 3rd-party JS libraries (Velocity.js, etc …)

Very full of divine libs that people still use, which is great, and you can feel free to call and use without worrying about missing.

Let’s find out how to use it.

Very simply, we only need to add the following:

You can test the example below:

example1

The important point that I want to mention here is that we can detect transition states to be able to adjust as desired.

Vue provides us with a transition class wrapper component , which allows us to add transitions that convert into or move to any element on the DOM.

When an element is wrapped (wrapped) in a transition component that has been added or deleted, Vue will follow 1 follow as follows:

  1. Vue will automatically retrieve any elements on the DOM that contain CSS with transition or animation. And then will be added / deleted at the appropriate time.
  2. Provide JavaScript Hooks and they will be called back at the appropriate time. (If anyone doesn’t know JS hook yet, check here )

Transition Classes

Vue provides 4 classes for enter / leave transitions of an element.

1. v-enter : Start the entry state.CSS and JS hook of this class defined from the previous will be applied to the element before being inserted or removed on a frame.

2. v-enter-active : Activate and end the status. Apply to the element before being inserted, removed when the transition / animation is completed.

3. v-leave : Start the element’s departure state. Apply CSS and JS hooks when the leave transition event is triggered, removed after 1 frame.

4. v-leave-active : Activation and finish leave transition. Applied when the leave transitiion event is triggered, removed when the transition / animation is completed.

fcebf64696d0aaf9c841a15e7ca14685e8090615

We have a small example of JS hooks used to combine the same CSS transition:

in js file:

==> We can fully define JS hooks for processing combined with CSS Transition classes to create the best effects for insert, remove events or any event that relates to the transition element, component on DOM.

Join the Machine Learning event - Technology of the Future!
Join the Machine Learning event – Technology of the Future!

1 transition example, this is the familiar game Lazy Sudoku (: D)

DEMO here: Sudoku

In the above example, we have used the 3rd-party js as lodash, surely if anyone works a lot with js and wants to handle the array operation much, this libs will be used :), here the shuffle function will randomize arrays 1 randomly.

And also in the example there are initisze css classes and css transition classes to create animate for elements. And css transition + js hook Vue apply to transition-group . It’s easy to understand :).

Above is the basic knowledge I want to introduce to you about this new feature of Vue.1, a very good tool for creating effects, making our web application smoother and more professional. .

Hopefully the article will help you part in using effects for your application. See you in the following articles.:D

ITZone via Viblo

Share the news now