Javascript image rotation

Source: Internet
Author: User
1   <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  > 
2 < Html Xmlns = "Http://www.w3.org/1999/xhtml" >
3 < Head >
4 < Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" />
5 < Title > Simple image rotation </ Title >
6 < Style Type = "Text/CSS" >
7 * {
8 Margin : 0 ;
9 Padding : 0 ;
10 }
11
12 # Banner {
13 Position : Relative ;
14 Width : 954px ;
15 Height : 198px ;
16 Margin : 5px auto ;
17 Border : 2px solid # f00 ;
18 }
19 # Banner Div {
20 Position : Absolute ;
21 }
22 </ Style >
23
24 < Script Type = "Text/JavaScript" >
25 VaR Minnum = 1 ; // Start number
26 VaR Maxnum = 3 ; // End count
27 VaR Nownum = 1 ; // Current number
28 Function Changepic (){
29 For ( VaR I = Minnum; I <= Maxnum; I ++ ){
30 If (Nownum = I)
31 Document. getelementbyid ( " Mypic " ). SRC = " Images/banner_img " + I + " . Jpg " ;
32 }
33 Nownum ++ ;
34 If (Nownum = (Maxnum + 1 )){
35 Nownum = 1 ;
36 }
37 Window. setTimeout (changepic, 3000 );
38 }
39
40 </ Script >
41 </ Head >
42
43 < Body >
44 < Ul >
45 < Li ID = "Banner" >
46 < Div >
47 < A Href = "#" >
48 < IMG SRC = "Images/banner_img1.gif" ID = "Mypic" />
49 </ A >
50 </ Div >
51 </ Li >
52 </ Ul >
53 </ Body >
54 </ Html >

This is a simple image rotation.Code.

ID is set for IMG. In JavaScript, use document. getelementbyid (""). SRC to get the IMG path and modify it.

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.