1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8" />
    5. <style type="text/css">
    6. .main{
    7. width: 500px;
    8. height: 500px;
    9. }
    10. #container {
    11. position: relative;
    12. width: 550px;
    13. height: 252px;
    14. border: 3px solid #333;
    15. overflow: hidden;
    16. }
    17. #list {
    18. position: absolute;
    19. z-index: 1;
    20. width: 1100px;
    21. height: 252px;
    22. display:flex;
    23. }
    24. #list img {
    25. width: 550px;
    26. }
    27. .arrow {
    28. display:block;
    29. position: absolute;
    30. top: 105px;
    31. z-index: 2;
    32. display: none;
    33. width: 20px;
    34. height: 40px;
    35. font-size: 36px;
    36. font-weight: bold;
    37. line-height: 37px;
    38. text-align: center;
    39. color: #fff;
    40. cursor: pointer;
    41. }
    42. #container:hover .arrow {
    43. display: block;
    44. }
    45. #prev {
    46. left: 3px;
    47. }
    48. #next {
    49. right: 20px;
    50. }
    51. </style>
    52. </head>
    53. <body>
    54. <div id="container">
    55. <div id="list" style="left:0px;">
    56. <img src="res/htmlLX/gunbo1.jpg" />
    57. <img src="res/htmlLX/gunbo2.jpg" />
    58. </div>
    59. <span id="prev" class="arrow" onclick="last()"></span>
    60. <span id="next" class="arrow" onclick="next()"></span>
    61. </div>
    62. <script>
    63. var list = document.getElementById('list');
    64. //上一个
    65. function last() {
    66. var a = parseInt(list.style.left)
    67. if(a === 0){
    68. list.style.left = -550 + "px";
    69. }
    70. else if(a = -550){
    71. list.style.left = 0 + "px";
    72. }
    73. }
    74. //下一个
    75. function next() {
    76. var a = parseInt(list.style.left)
    77. if(a === 0){
    78. list.style.left = -550 + "px";
    79. }
    80. else if(a = -550){
    81. list.style.left = 0 + "px";
    82. }
    83. }
    84. //第二个方法
    85. function last() {
    86. var newleft = parseInt(list.style.left) + 550;
    87. list.style.left = newleft + "px";
    88. if(newleft > 0){
    89. list.style.left = -550 + "px";
    90. }
    91. }
    92. function next() {
    93. var newleft = parseInt(list.style.left) - 550;
    94. list.style.left = newleft + "px";
    95. if(newleft < -550){
    96. list.style.left = 0 + "px";
    97. }
    98. }
    99. </script>
    100. </body>
    101. </html>

    2021-09-25_160918.jpg2021-09-25_160937.jpg