如何调整 3-D Image Slider Carousel 以在幻灯片之间正确转换?

How can I adjust the 3-D Image Slider Carousel to transition between slides correctly?

使用 https://codepen.io/fghty/pen/JjJZreX 中的代码,我正在尝试向第 5 张幻灯片添加 3 张幻灯片 HTML 3-D 图像滑块轮播。

我添加了图像,然后映射了幻灯片 CSS,但是它不能像 5 张幻灯片示例那样在幻灯片之间正确转换,第一个选中的图像显示为前 6 张幻灯片。

如何调整我的代码,使 8 张幻灯片按照 5 张幻灯片的示例过渡?

<html>

            <style media="screen">
                body {
              margin: 0;
              background: #EEE;
              user-select: none;
              font-family: sans-serif;
            }


            #slider {
              position: relative;
              width: 50%;
              height: 32vw;
              margin: 150px auto;
              font-family: 'Helvetica Neue', sans-serif;
              perspective: 1400px;
              transform-style: preserve-3d;
            }

            input[type=radio] {
              position: relative;
              top: 108%;
              left: 50%;
              width: 18px;
              height: 18px;
              margin: 0 15px 0 0;
              opacity: 0.4;
              transform: translateX(-83px);
              cursor: pointer;
            }


            input[type=radio]:nth-child(8) {
              margin-right: 0px;
            }

            input[type=radio]:checked {
              opacity: 1;
            }




            #slider label,
            #slider label img {
              position: absolute;
              width: 100%;
              height: 100%;
              left: 0;
              top: 0;
              color: white;
              font-size: 70px;
              font-weight: bold;
              border-radius: 3px;
              cursor: pointer;
              display: flex;
              align-items: center;
              justify-content: center;
              transition: transform 400ms ease;
            }



            /* Slider Functionality */

            /* Active Slide */
            #s1:checked ~ #slide1,
             #s2:checked ~ #slide2,
              #s3:checked ~ #slide3,
               #s4:checked ~ #slide4,
                #s5:checked ~ #slide5,
                /* add new slides*/
                 #s6:checked ~ #slide6,
               #s7:checked ~ #slide7,
                #s8:checked ~ #slide8 {
              box-shadow: 0 13px 26px rgba(0,0,0, 0.3), 0 12px 6px rgba(0,0,0, 0.2);
              transform: translate3d(0%, 0, 0px);
            }

            /* Next Slide */
            #s1:checked ~ #slide2,
             #s2:checked ~ #slide3,
              #s3:checked ~ #slide4,
               #s4:checked ~ #slide5,
                #s5:checked ~ #slide6,
                /* add new slides*/
                #s6:checked ~ #slide7,
               #s7:checked ~ #slide8,
                #s8:checked ~ #slide1{
              box-shadow: 0 6px 10px rgba(0,0,0, 0.3), 0 2px 2px rgba(0,0,0, 0.2);
              transform: translate3d(20%, 0, -100px);
            }


            /* Next to Next Slide */
            #s1:checked ~ #slide3,
             #s2:checked ~ #slide4,
              #s3:checked ~ #slide5,
               #s4:checked ~ #slide1,
                #s5:checked ~ #slide2,
                /* add new slides*/
                 #s6:checked ~ #slide3,
               #s7:checked ~ #slide4,
                #s8:checked ~ #slide5
                
                {
              box-shadow: 0 1px 4px rgba(0,0,0, 0.4);
              transform: translate3d(40%, 0, -250px);
            }

            /* Previous to Previous Slide */
            #s1:checked ~ #slide4,
             #s2:checked ~ #slide5,
              #s3:checked ~ #slide1,
               #s4:checked ~ #slide2,
                #s5:checked ~ #slide3,
                /* add new slides*/
                 #s6:checked ~ #slide4,
               #s7:checked ~ #slide5,
                #s8:checked ~ #slide6
                {
              box-shadow: 0 1px 4px rgba(0,0,0, 0.4);
              transform: translate3d(-40%, 0, -250px);
            }

            /* Previous Slide */
            #s1:checked ~ #slide5,
             #s2:checked ~ #slide1,
              #s3:checked ~ #slide2,
               #s4:checked ~ #slide3,
                #s5:checked ~ #slide4,
                /* add new slides*/
                #s6:checked ~ #slide5,
               #s7:checked ~ #slide6,
                #s8:checked ~ #slide7{
              box-shadow: 0 6px 10px rgba(0,0,0, 0.3), 0 2px 2px rgba(0,0,0, 0.2);
              transform: translate3d(-20%, 0, -100px);
            }


              </style>
            </head>
            <body>
            <section id="slider">
              <input type="radio" name="slider" id="s1" checked>
              <input type="radio" name="slider" id="s2">
              <input type="radio" name="slider" id="s3">
              <input type="radio" name="slider" id="s4">
              <input type="radio" name="slider" id="s5">
              <input type="radio" name="slider" id="s6">
              <input type="radio" name="slider" id="s7">
               <input type="radio" name="slider" id="s8">
             

              <label for="s1" id="slide1"><img src="https://img.freepik.com/free-photo/empty-sea-beach-background_74190-313.jpg?size=626&ext=jpg" alt=""></label>
              <label for="s2" id="slide2"><img src="https://t4.ftcdn.net/jpg/03/09/56/17/360_F_309561741_65AVmSUj9PuybfZFo2McgkOw6jTxfCtc.jpg" alt=""></label>
              <label for="s3" id="slide3"><img src="https://thumbs.dreamstime.com/b/sunrise-over-beach-cancun-beautiful-mexico-40065727.jpg" alt=""></label>
              <label for="s4" id="slide4"><img src="https://media.istockphoto.com/photos/couple-relax-on-the-beach-enjoy-beautiful-sea-on-the-tropical-island-picture-id1160947136?k=20&m=1160947136&s=612x612&w=0&h=TdExAS2--H3tHQv2tc5woAl7e0zioUVB5dbIz6At0I4=" alt=""></label>
              <label for="s5" id="slide5"><img src="https://image.shutterstock.com/image-photo/chairs-umbrella-palm-beach-tropical-260nw-559599520.jpg" alt=""></label>
               <label for="s3" id="slide6"><img src="https://media.istockphoto.com/photos/tropical-beach-in-punta-cana-dominican-republic-caribbean-island-picture-id1150862958?b=1&k=20&m=1150862958&s=170667a&w=0&h=Fp6mNIh4pWJBBnm4dkpQfi-rjU-9D-HzEAV5Zgyc6wE=" alt=""></label>
              <label for="s4" id="slide7"><img src="https://cdn.pixabay.com/photo/2016/10/18/21/22/beach-1751455__480.jpg" alt=""></label>
              <label for="s5" id="slide8"><img src="https://img.freepik.com/free-photo/beautiful-tropical-empty-beach-sea-ocean-with-white-cloud-blue-sky-background_74190-13665.jpg?size=626&ext=jpg" alt=""></label>
            </section>


</html>

这里是 5 张幻灯片的工作示例以供比较:

    <style media="screen">
    body {
  margin: 0;
  background: #EEE;
  user-select: none;
  font-family: sans-serif;
}


#slider {
  position: relative;
  width: 50%;
  height: 32vw;
  margin: 150px auto;
  font-family: 'Helvetica Neue', sans-serif;
  perspective: 1400px;
  transform-style: preserve-3d;
}

input[type=radio] {
  position: relative;
  top: 108%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: 0 15px 0 0;
  opacity: 0.4;
  transform: translateX(-83px);
  cursor: pointer;
}


input[type=radio]:nth-child(5) {
  margin-right: 0px;
}

input[type=radio]:checked {
  opacity: 1;
}




#slider label,
#slider label img {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  color: white;
  font-size: 70px;
  font-weight: bold;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 400ms ease;
}



/* Slider Functionality */

/* Active Slide */
#s1:checked ~ #slide1,
 #s2:checked ~ #slide2,
  #s3:checked ~ #slide3,
   #s4:checked ~ #slide4,
    #s5:checked ~ #slide5 {
  box-shadow: 0 13px 26px rgba(0,0,0, 0.3), 0 12px 6px rgba(0,0,0, 0.2);
  transform: translate3d(0%, 0, 0px);
}

/* Next Slide */
#s1:checked ~ #slide2,
 #s2:checked ~ #slide3,
  #s3:checked ~ #slide4,
   #s4:checked ~ #slide5,
    #s5:checked ~ #slide1 {
  box-shadow: 0 6px 10px rgba(0,0,0, 0.3), 0 2px 2px rgba(0,0,0, 0.2);
  transform: translate3d(20%, 0, -100px);
}


/* Next to Next Slide */
#s1:checked ~ #slide3,
 #s2:checked ~ #slide4,
  #s3:checked ~ #slide5,
   #s4:checked ~ #slide1,
    #s5:checked ~ #slide2 {
  box-shadow: 0 1px 4px rgba(0,0,0, 0.4);
  transform: translate3d(40%, 0, -250px);
}

/* Previous to Previous Slide */
#s1:checked ~ #slide4,
 #s2:checked ~ #slide5,
  #s3:checked ~ #slide1,
   #s4:checked ~ #slide2,
    #s5:checked ~ #slide3 {
  box-shadow: 0 1px 4px rgba(0,0,0, 0.4);
  transform: translate3d(-40%, 0, -250px);
}

/* Previous Slide */
#s1:checked ~ #slide5,
 #s2:checked ~ #slide1,
  #s3:checked ~ #slide2,
   #s4:checked ~ #slide3,
    #s5:checked ~ #slide4 {
  box-shadow: 0 6px 10px rgba(0,0,0, 0.3), 0 2px 2px rgba(0,0,0, 0.2);
  transform: translate3d(-20%, 0, -100px);
}


  </style>
</head>
<body>
<section id="slider">
  <input type="radio" name="slider" id="s1" checked>
  <input type="radio" name="slider" id="s2">
  <input type="radio" name="slider" id="s3">
  <input type="radio" name="slider" id="s4">
  <input type="radio" name="slider" id="s5">

  <label for="s1" id="slide1"><img src="https://i.pinimg.com/originals/2b/de/de/2bdede0647e3cdf75b44ea33723201d9.jpg" alt=""></label>
  <label for="s2" id="slide2"><img src="https://images6.alphacoders.com/462/thumb-1920-462371.jpg" alt=""></label>
  <label for="s3" id="slide3"><img src="https://wallpaperaccess.com/full/1154341.jpg" alt=""></label>
  <label for="s4" id="slide4"><img src="https://wallpapercave.com/wp/wp2634222.jpg" alt=""></label>
  <label for="s5" id="slide5"><img src="https://images5.alphacoders.com/343/thumb-1920-343645.jpg" alt=""></label>
</section>

您有错误的 id,错误的 tranlate3d 值,并且您忘记添加额外的检查 id 来说明您的 3 张额外的幻灯片。下面的代码片段现在应该可以使用了。

<html>

  <style media="screen">
    body {
      margin: 0;
      background: #EEE;
      user-select: none;
      font-family: sans-serif;
    }

    <style media="screen">body {
      margin: 0;
      background: #EEE;
      user-select: none;
      font-family: sans-serif;
    }

    #slider {
      position: relative;
      width: 50%;
      height: 32vw;
      margin: 150px auto;
      font-family: 'Helvetica Neue', sans-serif;
      perspective: 1400px;
      transform-style: preserve-3d;
    }

    input[type=radio] {
      position: relative;
      top: 108%;
      left: 50%;
      width: 18px;
      height: 18px;
      margin: 0 15px 0 0;
      opacity: 0.4;
      transform: translateX(-83px);
      cursor: pointer;
    }

    input[type=radio]:nth-child(8) {
      margin-right: 0px;
    }

    input[type=radio]:checked {
      opacity: 1;
    }

    #slider label,
    #slider label img {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
      color: white;
      font-size: 70px;
      font-weight: bold;
      border-radius: 3px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: transform 400ms ease;
    }

    /* Slider Functionality */
    /* Active Slide */
    #s1:checked~#slide1,
    #s2:checked~#slide2,
    #s3:checked~#slide3,
    #s4:checked~#slide4,
    #s5:checked~#slide5,
    /* add new slides*/
    #s6:checked~#slide6,
    #s7:checked~#slide7,
    #s8:checked~#slide8 {
      box-shadow: 0 13px 26px rgba(0, 0, 0, 0.3), 0 12px 6px rgba(0, 0, 0, 0.2);
      transform: translate3d(0%, 0, 0px);
    }

    /* Next Slide */
    #s1:checked~#slide2,
    #s2:checked~#slide3,
    #s3:checked~#slide4,
    #s4:checked~#slide5,
    #s5:checked~#slide6,
    /* add new slides*/
    #s6:checked~#slide7,
    #s7:checked~#slide8,
    #s8:checked~#slide1 {
      box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3), 0 2px 2px rgba(0, 0, 0, 0.2);
      transform: translate3d(20%, 0, -100px);
    }

    /* Next to Next Slide */
    #s1:checked~#slide3,
    #s2:checked~#slide4,
    #s3:checked~#slide5,
    #s4:checked~#slide6,
    #s5:checked~#slide7,
    /* add new slides*/
    #s6:checked~#slide8,
    #s7:checked~#slide1,
    #s8:checked~#slide2 {
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
      transform: translate3d(40%, 0, -250px);
    }

    /* Previous to Previous Slide */
    #s1:checked~#slide4,
    #s2:checked~#slide5,
    #s3:checked~#slide6,
    #s4:checked~#slide7,
    #s5:checked~#slide8,
    /* add new slides*/
    #s6:checked~#slide1,
    #s7:checked~#slide2,
    #s8:checked~#slide3 {
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
      transform: translate3d(-40%, 0, -250px);
    }
    
    /* Previous to Previous Slide */
    #s1:checked~#slide5,
    #s2:checked~#slide6,
    #s3:checked~#slide7,
    #s4:checked~#slide8,
    #s5:checked~#slide1,
    /* add new slides*/
    #s6:checked~#slide2,
    #s7:checked~#slide3,
    #s8:checked~#slide4 {
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
      transform: translate3d(-40%, 0, -250px);
    }
    
    #s1:checked~#slide6,
    #s2:checked~#slide7,
    #s3:checked~#slide8,
    #s4:checked~#slide1,
    #s5:checked~#slide2,
    /* add new slides*/
    #s6:checked~#slide3,
    #s7:checked~#slide4,
    #s8:checked~#slide5 {
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
      transform: translate3d(-40%, 0, -250px);
    }
    
    #s1:checked~#slide7,
    #s2:checked~#slide8,
    #s3:checked~#slide1,
    #s4:checked~#slide2,
    #s5:checked~#slide3,
    /* add new slides*/
    #s6:checked~#slide4,
    #s7:checked~#slide5,
    #s8:checked~#slide6 {
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
      transform: translate3d(-40%, 0, -250px);
    }
    
    #s1:checked~#slide8,
    #s2:checked~#slide1,
    #s3:checked~#slide2,
    #s4:checked~#slide3,
    #s5:checked~#slide4,
    /* add new slides*/
    #s6:checked~#slide5,
    #s7:checked~#slide6,
    #s8:checked~#slide7 {
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
      transform: translate3d(-20%, 0, -100px);
    }
  </style>
</head>

<body>
  <section id="slider">
    <input type="radio" name="slider" id="s1" checked>
    <input type="radio" name="slider" id="s2">
    <input type="radio" name="slider" id="s3">
    <input type="radio" name="slider" id="s4">
    <input type="radio" name="slider" id="s5">
    <input type="radio" name="slider" id="s6">
    <input type="radio" name="slider" id="s7">
    <input type="radio" name="slider" id="s8">

    <label for="s1" id="slide1"><img src="https://img.freepik.com/free-photo/empty-sea-beach-background_74190-313.jpg?size=626&ext=jpg" alt=""></label>
    <label for="s2" id="slide2"><img src="https://t4.ftcdn.net/jpg/03/09/56/17/360_F_309561741_65AVmSUj9PuybfZFo2McgkOw6jTxfCtc.jpg" alt=""></label>
    <label for="s3" id="slide3"><img src="https://thumbs.dreamstime.com/b/sunrise-over-beach-cancun-beautiful-mexico-40065727.jpg" alt=""></label>
    <label for="s4" id="slide4"><img src="https://media.istockphoto.com/photos/couple-relax-on-the-beach-enjoy-beautiful-sea-on-the-tropical-island-picture-id1160947136?k=20&m=1160947136&s=612x612&w=0&h=TdExAS2--H3tHQv2tc5woAl7e0zioUVB5dbIz6At0I4=" alt=""></label>
    <label for="s5" id="slide5"><img src="https://image.shutterstock.com/image-photo/chairs-umbrella-palm-beach-tropical-260nw-559599520.jpg" alt=""></label>
    <label for="s6" id="slide6"><img src="https://media.istockphoto.com/photos/tropical-beach-in-punta-cana-dominican-republic-caribbean-island-picture-id1150862958?b=1&k=20&m=1150862958&s=170667a&w=0&h=Fp6mNIh4pWJBBnm4dkpQfi-rjU-9D-HzEAV5Zgyc6wE=" alt=""></label>
    <label for="s7" id="slide7"><img src="https://cdn.pixabay.com/photo/2016/10/18/21/22/beach-1751455__480.jpg" alt=""></label>
    <label for="s8" id="slide8"><img src="https://img.freepik.com/free-photo/beautiful-tropical-empty-beach-sea-ocean-with-white-cloud-blue-sky-background_74190-13665.jpg?size=626&ext=jpg" alt=""></label>
  </section>


    </html>