html 只有第一个轮播的工作出一个多个在同一页

mm9b1k5b  于 2024-01-04  发布在  其他
关注(0)|答案(1)|浏览(220)

我尝试添加for循环来遍历每个carousel,但是当我这样做的时候,现在它们都不工作了。在我添加for循环之前,只有第一个工作。
最初是:

  1. querySelector('.carousel')

字符串
然后我把它改成:

  1. querySelectorAll('.carousel')

  1. var carousel = document.querySelectorAll('.carousel'), i;
  2. for (i = 0; i < carousel.length; ++i) {
  3. firstImg = carousel[i].querySelectorAll("img")[0];
  4. arrowIcons = document.querySelectorAll(".wrapper i");
  5. let isDragStart = false, isDragging = false, prevPageX, prevScrollLeft, positionDiff;
  6. carousel[i].addEventListener("mousedown", dragStart);
  7. carousel[i].addEventListener("touchstart", dragStart);
  8. document.addEventListener("mousemove", dragging);
  9. carousel[i].addEventListener("touchmove", dragging);
  10. document.addEventListener("mouseup", dragStop);
  11. carousel[i].addEventListener("touchend", dragStop);
  12. }
  13. const showHideIcons = () => {
  14. // showing and hiding prev/next icon according to carousel scroll left value
  15. let scrollWidth = carousel.scrollWidth - carousel.clientWidth; // getting max scrollable width
  16. arrowIcons[0].style.display = carousel.scrollLeft == 0 ? "none" : "block";
  17. arrowIcons[1].style.display = carousel.scrollLeft == scrollWidth ? "none" : "block";
  18. }
  19. arrowIcons.forEach(icon => {
  20. icon.addEventListener("click", () => {
  21. let firstImgWidth = firstImg.clientWidth + 14; // getting first img width & adding 14 margin value
  22. // if clicked icon is left, reduce width value from the carousel scroll left else add to it
  23. carousel.scrollLeft += icon.id == "left" ? -firstImgWidth : firstImgWidth;
  24. setTimeout(() => showHideIcons(), 60); // calling showHideIcons after 60ms
  25. });
  26. });
  27. const autoSlide = () => {
  28. // if there is no image left to scroll then return from here
  29. if(carousel.scrollLeft - (carousel.scrollWidth - carousel.clientWidth) > -1 || carousel.scrollLeft <= 0) return;
  30. positionDiff = Math.abs(positionDiff); // making positionDiff value to positive
  31. let firstImgWidth = firstImg.clientWidth + 14;
  32. // getting difference value that needs to add or reduce from carousel left to take middle img center
  33. let valDifference = firstImgWidth - positionDiff;
  34. if(carousel.scrollLeft > prevScrollLeft) { // if user is scrolling to the right
  35. return carousel.scrollLeft += positionDiff > firstImgWidth / 3 ? valDifference : -positionDiff;
  36. }
  37. // if user is scrolling to the left
  38. carousel.scrollLeft -= positionDiff > firstImgWidth / 3 ? valDifference : -positionDiff;
  39. }
  40. const dragStart = (e) => {
  41. // updatating global variables value on mouse down event
  42. isDragStart = true;
  43. prevPageX = e.pageX || e.touches[0].pageX;
  44. prevScrollLeft = carousel.scrollLeft;
  45. }
  46. const dragging = (e) => {
  47. // scrolling images/carousel to left according to mouse pointer
  48. if(!isDragStart) return;
  49. e.preventDefault();
  50. isDragging = true;
  51. carousel.classList.add("dragging");
  52. positionDiff = (e.pageX || e.touches[0].pageX) - prevPageX;
  53. carousel.scrollLeft = prevScrollLeft - positionDiff;
  54. showHideIcons();
  55. }
  56. const dragStop = () => {
  57. isDragStart = false;
  58. carousel.classList.remove("dragging");
  59. if(!isDragging) return;
  60. isDragging = false;
  61. autoSlide();
  62. }
  1. /* Import Google font - Poppins */
  2. @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
  3. *{
  4. margin: 0;
  5. padding: 0;
  6. box-sizing: border-box;
  7. font-family: 'Poppins', sans-serif;
  8. }
  9. body{
  10. //display: flex;
  11. padding: 0 35px;
  12. min-height: 100vh;
  13. align-items: center;
  14. justify-content: center;
  15. background: #343F4F;
  16. }
  17. .wrapper{
  18. display: flex;
  19. max-width: 1200px;
  20. position: relative;
  21. }
  22. .wrapper i{
  23. top: 50%;
  24. height: 44px;
  25. width: 44px;
  26. color: #343F4F;
  27. cursor: pointer;
  28. font-size: 1.15rem;
  29. position: absolute;
  30. text-align: center;
  31. line-height: 44px;
  32. background: #fff;
  33. border-radius: 50%;
  34. transform: translateY(-50%);
  35. transition: transform 0.1s linear;
  36. }
  37. .wrapper i:active{
  38. transform: translateY(-50%) scale(0.9);
  39. }
  40. .wrapper i:hover{
  41. background: #f2f2f2;
  42. }
  43. .wrapper i:first-child{
  44. left: -22px;
  45. display: none;
  46. }
  47. .wrapper i:last-child{
  48. right: -22px;
  49. }
  50. .wrapper .carousel{
  51. font-size: 0px;
  52. cursor: pointer;
  53. overflow: hidden;
  54. white-space: nowrap;
  55. scroll-behavior: smooth;
  56. }
  57. .carousel.dragging{
  58. cursor: grab;
  59. scroll-behavior: auto;
  60. }
  61. .carousel.dragging img{
  62. pointer-events: none;
  63. }
  64. .carousel img{
  65. height: 340px;
  66. object-fit: cover;
  67. user-select: none;
  68. margin-left: 14px;
  69. width: calc(100% / 3);
  70. }
  71. .carousel img:first-child{
  72. margin-left: 0px;
  73. }
  74. @media screen and (max-width: 900px) {
  75. .carousel img{
  76. width: calc(100% / 2);
  77. }
  78. }
  79. @media screen and (max-width: 550px) {
  80. .carousel img{
  81. width: 100%;
  82. }
  83. }
  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Draggable Image Slider | CodingNepal</title>
  6. <link rel="stylesheet" href="style.css">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
  9. </head>
  10. <body>
  11. <div>
  12. <div class="wrapper">
  13. <i id="left" class="fa-solid fa-angle-left"></i>
  14. <div class="carousel">
  15. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back04.jpg" alt="img" draggable="false">
  16. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back02.jpg" alt="img" draggable="false">
  17. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back01.jpg" alt="img" draggable="false">
  18. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back05.jpg" alt="img" draggable="false">
  19. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back07.jpg" alt="img" draggable="false">
  20. </div>
  21. <i id="right" class="fa-solid fa-angle-right"></i>
  22. </div>
  23. </div>
  24. <p>
  25. hihifdd
  26. </p>
  27. <div class="wrapper">
  28. <i id="left" class="fa-solid fa-angle-left"></i>
  29. <div class="carousel">
  30. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back04.jpg" alt="img" draggable="false">
  31. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back02.jpg" alt="img" draggable="false">
  32. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back01.jpg" alt="img" draggable="false">
  33. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back05.jpg" alt="img" draggable="false">
  34. <img src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back07.jpg" alt="img" draggable="false">
  35. </div>
  36. <i id="right" class="fa-solid fa-angle-right"></i>
  37. </div>
  38. </body>
  39. </html>
eanckbw9

eanckbw91#

您需要将其余函数带入for循环,并调整代码,以便函数引用当前循环中的carousel元素的属性:

  1. var carousel = document.querySelectorAll(".carousel"),
  2. i;
  3. for (i = 0; i < carousel.length; ++i) {
  4. const thisCourusel = carousel[i];
  5. const firstImg = thisCourusel.querySelectorAll("img")[0];
  6. const arrowIcons = thisCourusel.closest(".wrapper").querySelectorAll("i");
  7. let isDragStart = false,
  8. isDragging = false,
  9. prevPageX,
  10. prevScrollLeft,
  11. positionDiff;
  12. const dragStart = (e) => {
  13. // updatating global variables value on mouse down event
  14. isDragStart = true;
  15. prevPageX = e.pageX || e.touches[0].pageX;
  16. prevScrollLeft = thisCourusel.scrollLeft;
  17. };
  18. const dragging = (e) => {
  19. // scrolling images/carousel to left according to mouse pointer
  20. if (!isDragStart) return;
  21. e.preventDefault();
  22. isDragging = true;
  23. thisCourusel.classList.add("dragging");
  24. positionDiff = (e.pageX || e.touches[0].pageX) - prevPageX;
  25. thisCourusel.scrollLeft = prevScrollLeft - positionDiff;
  26. showHideIcons();
  27. };
  28. const dragStop = () => {
  29. isDragStart = false;
  30. thisCourusel.classList.remove("dragging");
  31. if (!isDragging) return;
  32. isDragging = false;
  33. autoSlide();
  34. };
  35. thisCourusel.addEventListener("mousedown", dragStart);
  36. thisCourusel.addEventListener("touchstart", dragStart);
  37. document.addEventListener("mousemove", dragging);
  38. thisCourusel.addEventListener("touchmove", dragging);
  39. document.addEventListener("mouseup", dragStop);
  40. thisCourusel.addEventListener("touchend", dragStop);
  41. const showHideIcons = () => {
  42. // showing and hiding prev/next icon according to carousel scroll left value
  43. let scrollWidth = thisCourusel.scrollWidth - thisCourusel.clientWidth; // getting max scrollable width
  44. arrowIcons[0].style.display =
  45. thisCourusel.scrollLeft == 0 ? "none" : "block";
  46. arrowIcons[1].style.display =
  47. thisCourusel.scrollLeft == scrollWidth ? "none" : "block";
  48. };
  49. arrowIcons.forEach((icon) => {
  50. icon.addEventListener("click", () => {
  51. let firstImgWidth = firstImg.clientWidth + 14; // getting first img width & adding 14 margin value
  52. // if clicked icon is left, reduce width value from the carousel scroll left else add to it
  53. thisCourusel.scrollLeft +=
  54. icon.id == "left" ? -firstImgWidth : firstImgWidth;
  55. setTimeout(() => showHideIcons(), 60); // calling showHideIcons after 60ms
  56. });
  57. });
  58. const autoSlide = () => {
  59. // if there is no image left to scroll then return from here
  60. if (
  61. thisCourusel.scrollLeft -
  62. (thisCourusel.scrollWidth - thisCourusel.clientWidth) >
  63. -1 ||
  64. thisCourusel.scrollLeft <= 0
  65. )
  66. return;
  67. positionDiff = Math.abs(positionDiff); // making positionDiff value to positive
  68. let firstImgWidth = firstImg.clientWidth + 14;
  69. // getting difference value that needs to add or reduce from carousel left to take middle img center
  70. let valDifference = firstImgWidth - positionDiff;
  71. if (carousel.scrollLeft > prevScrollLeft) {
  72. // if user is scrolling to the right
  73. return (thisCourusel.scrollLeft +=
  74. positionDiff > firstImgWidth / 3 ? valDifference : -positionDiff);
  75. }
  76. // if user is scrolling to the left
  77. thisCourusel.scrollLeft -=
  78. positionDiff > firstImgWidth / 3 ? valDifference : -positionDiff;
  79. };
  80. }
  1. /* Import Google font - Poppins */
  2. @import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap");
  3. * {
  4. margin: 0;
  5. padding: 0;
  6. box-sizing: border-box;
  7. font-family: "Poppins", sans-serif;
  8. }
  9. body {
  10. //display: flex;
  11. padding: 0 35px;
  12. min-height: 100vh;
  13. align-items: center;
  14. justify-content: center;
  15. background: #343f4f;
  16. }
  17. .wrapper {
  18. display: flex;
  19. max-width: 1200px;
  20. position: relative;
  21. }
  22. .wrapper i {
  23. top: 50%;
  24. height: 44px;
  25. width: 44px;
  26. color: #343f4f;
  27. cursor: pointer;
  28. font-size: 1.15rem;
  29. position: absolute;
  30. text-align: center;
  31. line-height: 44px;
  32. background: #fff;
  33. border-radius: 50%;
  34. transform: translateY(-50%);
  35. transition: transform 0.1s linear;
  36. }
  37. .wrapper i:active {
  38. transform: translateY(-50%) scale(0.9);
  39. }
  40. .wrapper i:hover {
  41. background: #f2f2f2;
  42. }
  43. .wrapper i:first-child {
  44. left: -22px;
  45. display: none;
  46. }
  47. .wrapper i:last-child {
  48. right: -22px;
  49. }
  50. .wrapper .carousel {
  51. font-size: 0px;
  52. cursor: pointer;
  53. overflow: hidden;
  54. white-space: nowrap;
  55. scroll-behavior: smooth;
  56. }
  57. .carousel.dragging {
  58. cursor: grab;
  59. scroll-behavior: auto;
  60. }
  61. .carousel.dragging img {
  62. pointer-events: none;
  63. }
  64. .carousel img {
  65. height: 340px;
  66. object-fit: cover;
  67. user-select: none;
  68. margin-left: 14px;
  69. width: calc(100% / 3);
  70. }
  71. .carousel img:first-child {
  72. margin-left: 0px;
  73. }
  74. @media screen and (max-width: 900px) {
  75. .carousel img {
  76. width: calc(100% / 2);
  77. }
  78. }
  79. @media screen and (max-width: 550px) {
  80. .carousel img {
  81. width: 100%;
  82. }
  83. }
  1. <!doctype html>
  2. <html lang="en" dir="ltr">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Draggable Image Slider | CodingNepal</title>
  6. <link rel="stylesheet" href="style.css" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8. <link
  9. rel="stylesheet"
  10. href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
  11. />
  12. </head>
  13. <body>
  14. <div>
  15. <div class="wrapper">
  16. <i id="left" class="fa-solid fa-angle-left"></i>
  17. <div class="carousel">
  18. <img
  19. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back04.jpg"
  20. alt="img"
  21. draggable="false"
  22. />
  23. <img
  24. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back02.jpg"
  25. alt="img"
  26. draggable="false"
  27. />
  28. <img
  29. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back01.jpg"
  30. alt="img"
  31. draggable="false"
  32. />
  33. <img
  34. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back05.jpg"
  35. alt="img"
  36. draggable="false"
  37. />
  38. <img
  39. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back07.jpg"
  40. alt="img"
  41. draggable="false"
  42. />
  43. </div>
  44. <i id="right" class="fa-solid fa-angle-right"></i>
  45. </div>
  46. </div>
  47. <p>hihifdd</p>
  48. <div class="wrapper">
  49. <i id="left" class="fa-solid fa-angle-left"></i>
  50. <div class="carousel">
  51. <img
  52. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back04.jpg"
  53. alt="img"
  54. draggable="false"
  55. />
  56. <img
  57. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back02.jpg"
  58. alt="img"
  59. draggable="false"
  60. />
  61. <img
  62. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back01.jpg"
  63. alt="img"
  64. draggable="false"
  65. />
  66. <img
  67. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back05.jpg"
  68. alt="img"
  69. draggable="false"
  70. />
  71. <img
  72. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back07.jpg"
  73. alt="img"
  74. draggable="false"
  75. />
  76. </div>
  77. <i id="right" class="fa-solid fa-angle-right"></i>
  78. </div>
  79. </body>
  80. </html>

您可能需要使用forEach()循环来使代码更清晰,例如:

  1. document.querySelectorAll(".carousel").forEach((carousel) => {
  2. const firstImg = carousel.querySelectorAll("img")[0];
  3. const arrowIcons = carousel.closest(".wrapper").querySelectorAll("i");
  4. let isDragStart = false,
  5. isDragging = false,
  6. prevPageX,
  7. prevScrollLeft,
  8. positionDiff;
  9. const dragStart = (e) => {
  10. // updatating global variables value on mouse down event
  11. isDragStart = true;
  12. prevPageX = e.pageX || e.touches[0].pageX;
  13. prevScrollLeft = carousel.scrollLeft;
  14. };
  15. const dragging = (e) => {
  16. // scrolling images/carousel to left according to mouse pointer
  17. if (!isDragStart) return;
  18. e.preventDefault();
  19. isDragging = true;
  20. carousel.classList.add("dragging");
  21. positionDiff = (e.pageX || e.touches[0].pageX) - prevPageX;
  22. carousel.scrollLeft = prevScrollLeft - positionDiff;
  23. showHideIcons();
  24. };
  25. const dragStop = () => {
  26. isDragStart = false;
  27. carousel.classList.remove("dragging");
  28. if (!isDragging) return;
  29. isDragging = false;
  30. autoSlide();
  31. };
  32. carousel.addEventListener("mousedown", dragStart);
  33. carousel.addEventListener("touchstart", dragStart);
  34. document.addEventListener("mousemove", dragging);
  35. carousel.addEventListener("touchmove", dragging);
  36. document.addEventListener("mouseup", dragStop);
  37. carousel.addEventListener("touchend", dragStop);
  38. const showHideIcons = () => {
  39. // showing and hiding prev/next icon according to carousel scroll left value
  40. let scrollWidth = carousel.scrollWidth - carousel.clientWidth; // getting max scrollable width
  41. arrowIcons[0].style.display = carousel.scrollLeft == 0 ? "none" : "block";
  42. arrowIcons[1].style.display =
  43. carousel.scrollLeft == scrollWidth ? "none" : "block";
  44. };
  45. arrowIcons.forEach((icon) => {
  46. icon.addEventListener("click", () => {
  47. let firstImgWidth = firstImg.clientWidth + 14; // getting first img width & adding 14 margin value
  48. // if clicked icon is left, reduce width value from the carousel scroll left else add to it
  49. carousel.scrollLeft += icon.id == "left" ? -firstImgWidth : firstImgWidth;
  50. setTimeout(() => showHideIcons(), 60); // calling showHideIcons after 60ms
  51. });
  52. });
  53. const autoSlide = () => {
  54. // if there is no image left to scroll then return from here
  55. if (
  56. carousel.scrollLeft - (carousel.scrollWidth - carousel.clientWidth) >
  57. -1 ||
  58. carousel.scrollLeft <= 0
  59. )
  60. return;
  61. positionDiff = Math.abs(positionDiff); // making positionDiff value to positive
  62. let firstImgWidth = firstImg.clientWidth + 14;
  63. // getting difference value that needs to add or reduce from carousel left to take middle img center
  64. let valDifference = firstImgWidth - positionDiff;
  65. if (carousel.scrollLeft > prevScrollLeft) {
  66. // if user is scrolling to the right
  67. return (carousel.scrollLeft +=
  68. positionDiff > firstImgWidth / 3 ? valDifference : -positionDiff);
  69. }
  70. // if user is scrolling to the left
  71. carousel.scrollLeft -=
  72. positionDiff > firstImgWidth / 3 ? valDifference : -positionDiff;
  73. };
  74. });
  1. /* Import Google font - Poppins */
  2. @import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap");
  3. * {
  4. margin: 0;
  5. padding: 0;
  6. box-sizing: border-box;
  7. font-family: "Poppins", sans-serif;
  8. }
  9. body {
  10. //display: flex;
  11. padding: 0 35px;
  12. min-height: 100vh;
  13. align-items: center;
  14. justify-content: center;
  15. background: #343f4f;
  16. }
  17. .wrapper {
  18. display: flex;
  19. max-width: 1200px;
  20. position: relative;
  21. }
  22. .wrapper i {
  23. top: 50%;
  24. height: 44px;
  25. width: 44px;
  26. color: #343f4f;
  27. cursor: pointer;
  28. font-size: 1.15rem;
  29. position: absolute;
  30. text-align: center;
  31. line-height: 44px;
  32. background: #fff;
  33. border-radius: 50%;
  34. transform: translateY(-50%);
  35. transition: transform 0.1s linear;
  36. }
  37. .wrapper i:active {
  38. transform: translateY(-50%) scale(0.9);
  39. }
  40. .wrapper i:hover {
  41. background: #f2f2f2;
  42. }
  43. .wrapper i:first-child {
  44. left: -22px;
  45. display: none;
  46. }
  47. .wrapper i:last-child {
  48. right: -22px;
  49. }
  50. .wrapper .carousel {
  51. font-size: 0px;
  52. cursor: pointer;
  53. overflow: hidden;
  54. white-space: nowrap;
  55. scroll-behavior: smooth;
  56. }
  57. .carousel.dragging {
  58. cursor: grab;
  59. scroll-behavior: auto;
  60. }
  61. .carousel.dragging img {
  62. pointer-events: none;
  63. }
  64. .carousel img {
  65. height: 340px;
  66. object-fit: cover;
  67. user-select: none;
  68. margin-left: 14px;
  69. width: calc(100% / 3);
  70. }
  71. .carousel img:first-child {
  72. margin-left: 0px;
  73. }
  74. @media screen and (max-width: 900px) {
  75. .carousel img {
  76. width: calc(100% / 2);
  77. }
  78. }
  79. @media screen and (max-width: 550px) {
  80. .carousel img {
  81. width: 100%;
  82. }
  83. }
  1. <!doctype html>
  2. <html lang="en" dir="ltr">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Draggable Image Slider | CodingNepal</title>
  6. <link rel="stylesheet" href="style.css" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8. <link
  9. rel="stylesheet"
  10. href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
  11. />
  12. </head>
  13. <body>
  14. <div>
  15. <div class="wrapper">
  16. <i id="left" class="fa-solid fa-angle-left"></i>
  17. <div class="carousel">
  18. <img
  19. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back04.jpg"
  20. alt="img"
  21. draggable="false"
  22. />
  23. <img
  24. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back02.jpg"
  25. alt="img"
  26. draggable="false"
  27. />
  28. <img
  29. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back01.jpg"
  30. alt="img"
  31. draggable="false"
  32. />
  33. <img
  34. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back05.jpg"
  35. alt="img"
  36. draggable="false"
  37. />
  38. <img
  39. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back07.jpg"
  40. alt="img"
  41. draggable="false"
  42. />
  43. </div>
  44. <i id="right" class="fa-solid fa-angle-right"></i>
  45. </div>
  46. </div>
  47. <p>hihifdd</p>
  48. <div class="wrapper">
  49. <i id="left" class="fa-solid fa-angle-left"></i>
  50. <div class="carousel">
  51. <img
  52. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back04.jpg"
  53. alt="img"
  54. draggable="false"
  55. />
  56. <img
  57. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back02.jpg"
  58. alt="img"
  59. draggable="false"
  60. />
  61. <img
  62. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back01.jpg"
  63. alt="img"
  64. draggable="false"
  65. />
  66. <img
  67. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back05.jpg"
  68. alt="img"
  69. draggable="false"
  70. />
  71. <img
  72. src="https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/back07.jpg"
  73. alt="img"
  74. draggable="false"
  75. />
  76. </div>
  77. <i id="right" class="fa-solid fa-angle-right"></i>
  78. </div>
  79. </body>
  80. </html>

这样做的好处是,您不会在carousel变量的命名之间产生不协调--我希望它对于集合carousel是复数。

展开查看全部

相关问题