Vue project tween method implementation returns the sample code at the top, vuetween

Source: Internet
Author: User

Vue project tween method implementation returns the sample code at the top, vuetween

I. Scenarios

Tween. js is a js animation library that can generate smooth animation effects.

What do you do when you want to implement the function of returning to the top? Most people will use document. body. scrollTop = 0. This write will implement the function,

But to be more delicate, we may wish to use the gentle movements of the tween to see how it works.

We have previously written a tween Article, which is not introduced here.

Ii. Code

<! DOCTYPE html> 

Iii. requestAnimationFrame rewrite the setInterval method:

Methods: {backTop () {var Tween = {Linear: function (t, B, c, d) {// return c * t/d + B at a constant speed;} Math. tween = Tween; var t = 1; const B = document. body. scrollTop; const c = 1; const d = 1; var timer; timer = requestAnimationFrame (function fn () {if (document. body. scrollTop> 0) {t --; console. log (t) console. log (t); const backTop = Tween. linear (t, B, c, d); console. log (backTop); document. body. scrollTop = backTop; timer = requestAnimationFrame (fn);} else {cancelAnimationFrame (timer )}})}}

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.