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.