简单的图片轮翻效果2
所需html代码如下:
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; charset=utf-8" /> 5 <title>用js来实现图片轮翻</title> 6 </head> 7 8 <body> 9 <img id="img1" src="images/1.jpg" /> 10 </body> 11 </html>
接下来是真正起作用的js代码
1 <script type="text/javascript"> 2 var i=1; 3 function init() 4 { 5 6 i++; 7 //获取id=img1的对象 8 var obj=document.getElementById("img1"); 9 obj.src="images/"+i+".jpg"; 10 window.setTimeout("init()",1000); 11 if(i>=6) 12 { 13 i=0; 14 } 15 } 16 </script>