JS animation effect (moving, change effect) to achieve finishing __js

Source: Internet
Author: User
Tags setinterval

such as in the first two blog results, the image deceleration slide to the designated position, in the Web page effect looks more beautiful, the user is more friendly, the effect of the implementation of the collation found a fixed pattern.

Implementation steps:

Define the current value of the property that needs to be modified: var = 0; Define the attribute target value that needs to be modified: var target = value; Define a Timer object: var timeinter= null; To loop through the pins with setinterval every 20 milliseconds modify the current value once the current value and target value are equal, the execution of the Stop SetInterval method is noteworthy, before each call to the SetInterval method To clear the previous setinterval, there will be multiple simultaneous runs. This can be understood as a Java thread, each run setinterval ran a small thread, and we want the effect is to run only one thread at a time, if not empty will cause multiple setinterval action on top of an object, making animation more quickly or other abnormal effects. The function of the timer Timeinter is to clear an unprecedented before the next setingerval run.


Code Structure Example:

var srcinter = null; 
var current = 0;
    Window.onscroll = function () {
        var target = =;
        Clearinterval (timeinter);
        Timeinter= setinterval (function () {Current
            = current + (target-current)/20;
            Obj.style.top = current+ "px";		Implement the move effect of the Obj object
        },20);
    }





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.