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.