目錄javascript
1.jpg
2.jpg
3.jpg
4.jpg
1.png
2.png
3.png
4.png
a1.png
a2.pngcss
我取名爲b1-2a1-4.css,其中b1和b2是左右選擇的按鈕,a1-4是跳轉到1到4中的一張圖的按鈕。html
.b1 { width: 62px; height: 94px; background: url(image/a1.png); position: absolute; top: 200px; left: 7px; } .b2 { width: 62px; height: 94px; background: url(image/a2.png); float: left; position: absolute; top: 200px; left: 677px; } .a1 { width: 29px; height: 29px; background: url(image/1.png); position: absolute; top: 420px; left: 600px; } .a2 { width: 29px; height: 29px; background: url(image/2.png); position: absolute; top: 420px; left: 630px; } .a3 { width: 29px; height: 29px; background: url(image/3.png); position: absolute; top: 420px; left: 660px; } .a4 { width: 29px; height: 29px; background: url(image/4.png); position: absolute; top: 420px; left: 690px; }
var i = 400; var img = document.getElementById("img1"); var timeID; timeID = setInterval("i++", 2000); function changeImg(i) { var imgs; if(i % 4 == 0) { imgs = "image/1.jpg"; } else if(i % 4 == 1) { imgs = "image/2.jpg"; } else if(i % 4 == 2) { imgs = "image/3.jpg"; } else { imgs = "image/4.jpg"; } return imgs; } function b1() { i--; var img = document.getElementById("img1"); img.src = changeImg(i); clearInterval(timeID); timeID = setInterval("i++", 2000); } function b2() { i++; var img = document.getElementById("img1"); img.src = changeImg(i); clearInterval(timeID); timeID = setInterval("i++", 2000); } function a1() { i = 400; var img = document.getElementById("img1"); img.src = changeImg(i); clearInterval(timeID); timeID = setInterval("i++", 2000); } function a2() { i = 401; var img = document.getElementById("img1"); img.src = changeImg(i); clearInterval(timeID); timeID = setInterval("i++", 2000); } function a3() { i = 402; var img = document.getElementById("img1"); img.src = changeImg(i); clearInterval(timeID); timeID = setInterval("i++", 2000); } function a4() { i = 403; var img = document.getElementById("img1"); img.src = changeImg(i); clearInterval(timeID); timeID = setInterval("i++", 2000); } function b3() { var img = document.getElementById("img1"); img.src = changeImg(i); } setInterval("b3()", 100);
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="b1-2a1-4.css" /> <script src="b1-3a1-4.js" type="text/javascript"></script> </head> <body> <img src="image/1.jpg" id="img1"/> <input type="button" class="b1" onclick="b1()"/> <input type="button" class="b2" onclick="b2()"/> <input type="button" class="a1" onclick="a1()"/> <input type="button" class="a2" onclick="a2()"/> <input type="button" class="a3" onclick="a3()"/> <input type="button" class="a4" onclick="a4()"/> </body> </html>
完工!(這實際上是以前作的,拿來湊數233333)話說我真的以爲挺好看的作的~java