Problems and solutions of using TweenMax animation library in angular

Problems and solutions of using TweenMax animation library in angular

I have nothing to do recently, so I tinker with CSS

I found a better animation library, TweenMax

It's a little cumbersome to use, but it really works.

First, to use TweenMax in angular, you must first install it through npm

1. npm install --save-dev gsap
2. npm install --save-dev @types/gsap

Then introduce

import {TweenMax} from "gsap";

You can use it in the page.

The first problem I encountered was that I wanted the animation to play continuously by triggering a button, but after the animation was played once, no matter how I clicked the button, it would not be triggered.

Later I found the reason. It is necessary to change its position when triggering repeatedly. For example, if X is 500 at the beginning, the position of X will be 500 after the animation is played. If it is triggered repeatedly, the position will still be 500, so it will not work. Therefore, if you want to trigger repeatedly, you have to change its position.

this.test = new TweenMax('.box',3,{
   x:this.direction?0:500,
   ease:Bounce.easeOut
  })

The second problem is that on the page, I want to change the state and text of the blue button during and after the animation, but I find that I cannot do this directly using the properties bound to the button.

<button [disabled]="isMoveing" style="margin-top: 10px;" nz-button nzType="primary" (click)="repeat()">
  {{describle}}
</button>

this.test = new TweenMax('.box',3,{
   x:this.direction?0:500,
   ease:Bounce.easeOut,
   onStart:function(){
    this.describle = 'In motion'
    this.isMoveing ​​= true
   },
   onComplete:function(){
    this.describle = 'Move'
    this.isMoveing ​​= false
   }
  })

After some trouble, I found that it was actually the problem pointed to by this

As can be seen in the figure above, in the TweenMax method, this points to the Tween method itself, and the object we need to change is in the component, as shown in the figure below

Once the problem is located, the solution is relatively simple. Just define an element outside the function scope to point to the correct this.

let _this = this
this.test = new TweenMax('.box',3,{
   x:this.direction?0:500,
   ease:Bounce.easeOut,
   onStart:function(){
    _this.describle = 'In motion'
    _this.isMoveing ​​= true
   },
   onComplete:function(){
    _this.describle = 'Move'
    _this.isMoveing ​​= false
   }
  })

That's normal.

Summarize

This is the end of this article about how to use TweenMax animation library in angular. For more information about how to use TweenMax in angular, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  An article to understand Linux disks and disk partitions

>>:  SQL method for calculating timestamp difference

Recommend

How to process local images dynamically loaded in Vue

Find the problem Today I encountered a problem of...

Steps to repair grub.cfg file corruption in Linux system

Table of contents 1. Introduction to grub.cfg fil...

Detailed explanation of TypeScript's basic types

Table of contents Boolean Type Number Types Strin...

Basic use of javascript array includes and reduce

Table of contents Preface Array.prototype.include...

Implementation of Docker deployment of MySQL cluster

Disadvantages of single-node database Large-scale...

Basic usage tutorial of MySQL slow query log

Slow query log related parameters MySQL slow quer...

A brief discussion on ifnull() function similar to nvl() function in MySQL

IFNULL(expr1,expr2) If expr1 is not NULL, IFNULL(...

Solve the installation problem of mysql8.0.19 winx64 version

MySQL is an open source, small relational databas...

Understanding of haslaylout and bfc parsing

1. haslayout and bfc are IE-specific and standard ...

The difference between html form submission action and url jump to actiond

The action of the form is different from the URL j...

Vue3.0 uses the vue-grid-layout plug-in to implement drag layout

Table of contents 1. Plugins 2. Interlude 3. Impl...

MySQL DML language operation example

Additional explanation, foreign keys: Do not use ...

Explanation of the problem that JavaScript strict mode does not support octal

Regarding the issue that JavaScript strict mode d...

How to use html table (to show the visual effect of web page)

We know that when using HTML on NetEase Blog, we ...