1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin: 0; padding: 0; } div{ width: 520px; height: 350px; border: aquamarine 2px solid; margin: 20px auto; position: relative; } div img{ position: absolute; left: 0; top: 0; opacity: 0; } div img:first-child{ opacity: 1; } .btn{ position: absolute; bottom: 0; width: 100%; height: 40px; border: none; text-align: center; } .btn p{ display: inline-block; width: 60px; height: 40px; text-align: center; line-height: 40px; background-color: gold; font-weight: bold; } </style> </head> <body> <div> <img src="img/t1.png"/> <img src="img/t2.jpg"/> <img src="img/t3.jpg"/> <img src="img/t4.jpg"/> <img src="img/t5.jpg"/> <div class="btn"> <p>图1</p> <p>图2</p> <p>图3</p> <p>图4</p> <p>图5</p> </div> </div> </body> </html> <script type="text/javascript"> var pArray = document.getElementsByTagName("p"); var imgArray = document.getElementsByTagName("img"); var index = 0; for(var i = 0; i < pArray.length; i++){ pArray[i].onclick = function(){ imgArray[index].style.opacity = 0; pArray[index].style.backgroundColor = "gold";
for(var j = 0; j < pArray.length; j++){ if(this == pArray[j]){ index = j; break; } } imgArray[index].style.opacity = 1; pArray[index].style.backgroundColor = "orange";
} } </script>
|