Analysis on the demand for random class name-based small applications using JavaScript

Source: Internet
Author: User

The requirements are as follows:

1. The name of all class personnel is displayed on the webpage.

2. Click the start button. The color of the person starts to change. When the person stops, there will be a different color position, so this position is the person who is clicked.

The graphic interface is roughly as follows:



The following is a detailed analysis of the above requirements:

1. initialize such a page and set the uniform color-green.

A. Name of the student, stored in array

B. display it with a div block on the page

2. Randomly select a location to change its color to-red.

A. Use css to control color changes

B. Random locations are generated using random functions.

3. In order to make it animated, set the interval to move the positions with different colors backward. And the color of the previous position is restored to green.

A. You need to design a method to change the color of the div, and call a method called at an interval when moving backwards. The settimeout and setinterval methods are available in js.

4. The animation effect should be stopped within the specified time, and the stop position is still red.

A. Stop the animation effect within the specified time. Actually, stop the above method. Using different methods in js has different implementation forms

5. After stopping at a certain position, a dialog box is displayed, showing who is the selected student.

A. The final result displayed by the Alert function is OK.

In the next section, we will implement javascript code for this small application.

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.