1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <title>点击轮播图</title>
    5. <meta charset="utf-8" />
    6. <style type="text/css">
    7. .main{
    8. width:600px;
    9. height:600px;
    10. }
    11. .h1{
    12. width:500px;
    13. height:300px;
    14. }
    15. .image_ul{
    16. list-style-type:none;
    17. margin:0px auto;
    18. padding:0px;
    19. width:600px;
    20. height:80px;
    21. display:flex;
    22. justify-content:space-between;
    23. }
    24. .show_btn{
    25. position:relative;
    26. width:16%;
    27. height:45px;
    28. opacity:0.7;
    29. }
    30. .active{
    31. position:relative;
    32. width:16%;
    33. height:45px;
    34. opacity:1;
    35. }
    36. img:hover{
    37. opacity:1;
    38. }
    39. </style>
    40. <script type="text/javascript">
    41. function show(e){
    42. //点击任意一张图片将这张图片的路径,赋给id"h1"的img标签
    43. document.getElementById('h1').src = e.src;
    44. //将所有class为“active”的存进一个数组,然后数组遍历全部class改为"show_btn"
    45. var arr=document.getElementsByClassName('active');
    46. for(var i=0;i<arr.length;i++){
    47. arr[i].className = 'show_btn';
    48. }
    49. //最后将本次点击的图片class改成“active”;
    50. e.className = 'active';
    51. }
    52. </script>
    53. </head>
    54. <body>
    55. <div class="main">
    56. <img id='h1' class="h1" src="res/htmlLX/gunbo1.jpg" />
    57. <div id="image_ul">
    58. <img id='li1' class="active" onclick='show(this)' src="res/htmlLX/gunbo1.jpg" />
    59. <img id='li2' class="show_btn" onclick='show(this)' src="res/htmlLX/gunbo2.jpg" />
    60. <img id='li3' class="show_btn" onclick='show(this)' src="res/htmlLX/gunbo3.jpg" />
    61. <img id='li4' class="show_btn" onclick='show(this)' src="res/htmlLX/gunbo4.jpg" />
    62. <img id='li5' class="show_btn" onclick='show(this)' src="res/htmlLX/gunbo5.jpg" />
    63. </div>
    64. </div>
    65. </body>
    66. </html>

    2021-09-25_154545.jpg