A simple animation effect implemented by native javascript, implemented by javascript

Source: Internet
Author: User

A simple animation effect implemented by native javascript, implemented by javascript

This article introduces an animation implemented by javascript. Click Start to move the div to the right. After you click STOP, The div stops moving, and then click continue to move. See the following code.

<! DOCTYPE html> 

Code explanation:


1. window. onload = function () {}, when the content of the document is fully loaded, run the code in the function.
2. var mydiv = document. getElementById ("mydiv") to obtain the element whose id attribute value is mydiv.
3. var start = document. getElementById ("start") to obtain the element whose id attribute hi is start.
4. var stopmove = document. getElementById ("stopmove") to obtain the element whose id attribute value is stopmove.
5. mydiv. style. left = x + "px", set the left attribute value of the div.
6. start. onclick = function () {}, Register The onclick event handler function for the start element.
7. clearInterval (flag): stop the timer function. If one party clicks the start button multiple times, the overlay effect is displayed.
8. flag = setInterval (move, 20) to start motion.

One simple animation effect implemented by the above native javascript is all the content shared by the editor. I hope to give you a reference and support for the help house.

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.