First stage: Front-end development _ using JS to complete the first page Carousel chart effect

Source: Internet
Author: User

2018-06-04

use JS to complete the first page Carousel chart effect

First, technical analysis

  get element: document.getElementById ("ID name")

 event (onload): page Load Event

  timed operation:setinterval ("changeimg ()", 3000);

Second, step analysis

First step: Determine the event (onload) and bind it to a function

Step Two: Write this function of the binding

Step three: Write timed tasks (setinterval)

Fourth step: Write the function inside the timed task

Fifth step: Loop through the variables (get the position of the carousel and set the SRC attribute) [Reset when you need to notice the last picture in the loop. ]

Third, the code implementation
 JS Code:

<script>functioninit () {//timing operation of the picture display of the writing wheelSetInterval ("changeimg ()", 3000); }    //writing function     varI=0;functionchangeimg () {i++;//get picture position and set src property valuedocument.getElementById ("Img1"). src= ". /img/small0 "+i+". jpg "; if(i==3) {i=0; }    } </script>

HTML code:

<onload= "init ()">

Defines the ID at the specified location.



First stage: Front-end development _ using JS to complete the first page Carousel chart effect

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.