In the previous article, we talked about the specific operation of JS array, see (JS to the array of various operations summary), here will no longer do a detailed explanation. The main purpose today is to use the array to make a simple switch around the picture.
The picture transitions in this article are specific steps:
The 1th step: simple layout and design basic display style;
2nd step: Through JS to obtain relevant elements;
3rd step: Through the array of image URL and corresponding text description of the storage;
The 4th step: initialization: Including the initialization of the picture, showing the image number and corresponding to the initialization of the text;
5th step: Click the button to switch pictures, write the corresponding function, in fact, is the simple array of applications.
Next, take a look at the effect map, and then explain the corresponding code.
Implementation code:
This example is very simple, the main is the simple reading and writing of the array and the content of HTML attributes read and write operations. It should be noted that when we click on the next to the last picture or click on the previous one to the first, you need to set specific numerical changes, not = Otherwise will cross, then the picture, number and the corresponding problem is not content.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.