Js image carousel implementation code and js Image Code

Source: Internet
Author: User

Js image carousel implementation code and js Image Code

First, let's take a look at the js image carousel effect, as shown in figure

Specific ideas:

I. page loading, obtaining the entire container, all the li s with numeric indexes, ul of the image list, defining the timer variables, and storing the index of the current index
2. Add a timer, increase the index every 2 seconds, and call the function to change the image.
Tip:
1. The index cannot be continuously incremented without limit. Therefore, you need to make a judgment.
2. When you call the image switching function, you must pass the incremental index as a parameter.
Iii. Define image switching functions
Tip:
1. traverse all the li s with numeric indexes and remove the classes on each li.
2. Find the corresponding li to add the class to it based on the passed index value and set it to the current highlighted display.
3. Calculate the ul top value of the Image Based on the passed index value.
4. Change the index value so that it is equal to the passed parameter value.
Note: The ul value of the image is-index * the height of a single image (the height must be high for all images)
4. When you move the mouse over the entire container, the image will stop switching and continue.
Tip:
1. Clear the timer when the mouse slides over the entire container
2. When the mouse leaves, continue to execute the timer and switch to the next image.
5. traverse all the numbers of li, add indexes to them, and switch to the corresponding image when the mouse slides.
When the mouse slides, the image switching function is called to pass over the index of li that has slipped.
The Code is as follows:

<! Doctype html> 

The above is all the content in this article. I have shared the js image carousel effect implementation code. I hope you will like it and change the image according to your preferences to create your own image carousel effect.

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.