Encapsulation of slow functions in JS carousel Images

Source: Internet
Author: User
This article describes in detail the encapsulation of slow functions in the JS carousel diagram, which has some reference value, interested friends can refer to the fact that the carousel diagram is essentially the encapsulation of the slow function. If the carousel diagram is a running car, the slow function is its engine, today, this article introduces you to simplify and simplify your own slow functions ~~

From the perspective of requirements, we first give a simple requirement:

1. How do I implement a box on the page that moves from the starting position to the right at a constant speed to the position of 200px?

Analysis:

1) We need to know where the box is located, which can be obtained through the offsetLeft attribute;

2) to keep the box moving at a constant speed, setInterval is required for js;

3) Do you want to run the box to the right? That is, we need to constantly change the distance between the box and the start point on the left, including the margin-left and the left of the positioning. Here we choose to change the left of the absolute positioning;

4) We have to stop the distance from the start point PX and use clearInterval.

Next, let's go directly to the code.

   
   Document       

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.