0

I want to be able to animate this code for a project I am working on. I can change the slides with the buttons but I also want it to stay on a slide for 30s then move to the next and pause on hover. I want the slides to repeat to. I am having a little issue with this. I am new to coding,

slide 1

your content here

Slide 2

your content here

slide 3

Your content here

‹ › ‹ › ‹ ›
  • <style>
    
    .carousel {
        border-style:solid;
        border-width:1px;
        border-color:rgba(0, 0, 0, 0.05);
        box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.1);
        widht:100%;
        height:250px;
    }
    
    .carousel-inner {
        position: relative;
        overflow: hidden;
        width: 100%;
        height:250px;
    }
    
    .carousel-open:checked + .carousel-item {
        position: absolute;
        opacity: 100;
        background-color:white;
        width:100%;
        height:250px;
    }
    
    .carousel-item {
        position: absolute;
        opacity: 0;
        padding-top:10px;
        text-align:center;
    }
    
    .carousel-control {
        background: rgba(0, 0, 0, 0);
        border-radius: 50%;
        color:#008c6c;
        cursor: pointer;
        display: none;
        font-size: 30px;
        height: 40px;
        line-height: 35px;
        position: absolute;
        top: 50%;
        -webkit-transform: translate(0, -50%);
        cursor: pointer;
        -ms-transform: translate(0, -50%);
        transform: translate(0, -50%);
        text-align: center;
        width: 40px;
        z-index: 10;
    }
    
    .carousel-control.prev {
        left: 2%;
    }
    
    .carousel-control.next {
        right: 2%;
    }
    
    .carousel-control:hover {
        background: rgba(0, 0, 0, 0.05);
        color: #008c6c;
    }
    
    #carousel-1:checked ~ .control-1,
    #carousel-2:checked ~ .control-2,
    #carousel-3:checked ~ .control-3 {
        display: block;
    }
    
    .carousel-indicators {
        margin: 0;
        padding: 0;
        position: absolute;
        bottom: 2px;
        left: 0;
        right: 0;
        text-align: center;
    }
    
    .carousel-indicators li {
        display: inline-block;
        margin: 0 5px;
    }
    
    .carousel-bullet {
        color: rgba(0, 0, 0, 0.05);
        cursor: pointer;
        font-size: 25px;
    }
    
    .carousel-bullet:hover {
        color: rgba(0, 0, 0, 0.1);
    }
    
    #carousel-1:checked ~ .control-1 ~ .carousel-indicators li:nth-child(1) .carousel-bullet,
    #carousel-2:checked ~ .control-2 ~ .carousel-indicators li:nth-child(2) .carousel-bullet,
    #carousel-3:checked ~ .control-3 ~ .carousel-indicators li:nth-child(3) .carousel-bullet {
        color: #008c6c;
    }
    
    #title {
        width: 100%;
        position: absolute;
        padding: 0px;
        margin: 0px auto;
        text-align: center;
        font-size: 27px;
        color: rgba(255, 255, 255, 1);
        font-family: 'Open Sans', sans-serif;
        z-index: 9999;
        text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.33), -1px 0px 2px rgba(255, 255, 255, 0);
    }
    .carousel li.carousel-1 {
      animation: cycle 30s linear infinite;
    }
    
    .carousel li.carousel-2 {
      animation: cycle2 30s linear infinite;
    }
    
    .carousel li.carousel-3 {
      animation: cycle3 30s linear infinite;
    }
    .carousel:hover li {
      animation-play-state: paused;
    }
    
    @keyframes cycle {
      0%   {top:    0px; opacity: 1; z-index:  1;}  /* Starts in view */
      30%  {top:    0px; opacity: 1; z-index:  1;}  /* In view */
      33%  {top:  325px; opacity: 0; z-index:  1;}  /* Slides out of view [to bottom] */
      63%  {top:  325px; opacity: 0; z-index: -1;}  /* Moves to back [z-index] */
      66%  {top: -325px; opacity: 0; z-index: -1;}  /* Moves back to top out of sight */ 
      96%  {top: -325px; opacity: 0; z-index:  1;}  /* Moves back to front [z-index] */
      100% {top:    0px; opacity: 1; z-index:  1;}  /* Return to start */
      }
      @keyframes cycle2 {
      0%   {top: -325px; opacity: 0; z-index: -1;}  /* Moves back to top out of sight */
      30%  {top: -325px; opacity: 0; z-index:  1;}  /* Moves back to front [z-index] */
      33%  {top:    0px; opacity: 1; z-index:  1;}  /* Slides into view [from top] */
      63%  {top:    0px; opacity: 1; z-index:  1;}  /* In view */
      66%  {top:  325px; opacity: 0; z-index:  1;}  /* Slides out of view [to bottom] */ 
      96%  {top:  325px; opacity: 0; z-index: -1;}  /* Moves to back [z-index] */
      100% {top: -325px; opacity: 0; z-index: -1;}  /* Return to start */
      }
      
      @keyframes cycle3 {
      0%   {top:  325px; opacity: 0; z-index:  1;}  /* Slides out of view [to bottom] */
      30%  {top:  325px; opacity: 0; z-index: -1;}  /* Moves to back [z-index] */
      33%  {top: -325px; opacity: 0; z-index: -1;}  /* Moves back to top out of sight */
      63%  {top: -325px; opacity: 0; z-index:  1;}  /* Moves back to front [z-index] */
      66%  {top:    0px; opacity: 1; z-index:  1;}  /* Slides into view [from top] */ 
      96%  {top:    0px; opacity: 1; z-index:  1;}  /* In view */
      100% {top:  325px; opacity: 0; z-index:  1;}  /* Return to start */
      }  
    
    </style>
    <div class="carousel"> 
       <div class="carousel-inner"> 
          <input name="carousel" class="carousel-open" id="carousel-1" aria-hidden="true" type="radio" hidden="true" Checked/> 
          <div class="carousel-item"> 
             <h1>slide 1</h1> 
             <p>your content here</p> 
          </div> 
          <input name="carousel" class="carousel-open" id="carousel-2" aria-hidden="true" type="radio" hidden="true"/> 
          <div class="carousel-item"> 
             <h1>Slide 2</h1> 
          <p>your content here</p> 
          </div> 
          <input name="carousel" class="carousel-open" id="carousel-3" aria-hidden="true" type="radio" hidden="true"/> 
          <div class="carousel-item"> 
             <h2>slide 3</h2> 
            <p>Your content here</p> 
          </div> 
         
          <label class="carousel-control prev control-1" for="carousel-3">‹</label>
          <label class="carousel-control next control-1" for="carousel-2">›</label>
          <label class="carousel-control prev control-2" for="carousel-1">‹</label>
          <label class="carousel-control next control-2" for="carousel-3">›</label>
          <label class="carousel-control prev control-3" for="carousel-2">‹</label>
          <label class="carousel-control next control-3" for="carousel-1">›</label> 
          <ol class="carousel-indicators"> 
             <li> 
                <label class="carousel-bullet" for="carousel-1">•</label> </li> 
             <li> 
                <label class="carousel-bullet" for="carousel-2">•</label> </li> 
             <li> 
                <label class="carousel-bullet" for="carousel-3">•</label> </li> 
    
          </ol> 
       </div> 
    </div>
            <label class="carousel-bullet" for="carousel-3">•</label> </li> 
    
      </ol> 
    
  • Spiers12
    • 19
    • 2
    • Did u tried key frames? Refer [this](https://stackoverflow.com/questions/16989585/css-3-slide-in-from-left-transition) and [this](https://www.w3.org/Style/Examples/007/slideshow.en.html) if you would like to try – Rajeshwar Aug 18 '21 at 13:03
    • 1
      To create a carousel with pause on hover, navigation and arrows - **the simplest you could do is use just a bit of JavaScript**. CSS is no meant to ease your job on such tasks. If you really want to have a glimpse on a CSS example (without autoslide) https://codepen.io/rokobuljan/pen/XXzqKQ from this answer http://stackoverflow.com/a/34696029/383904 – Roko C. Buljan Aug 18 '21 at 13:13
    • I have a different one that has jquery plug-in but the slide dots are messed up. I don't know enough about javascript to fix it. – Spiers12 Aug 31 '21 at 13:50

    0 Answers0