【问题标题】:start cssbased slider automatically?自动启动基于css的滑块?
【发布时间】:2015-02-16 10:45:29
【问题描述】:

我正在尝试创建一个仅 CSS 的滑块,效果很好。但是,我希望它自动启动并自动转换。这可能是通过css吗?

使用 html 和 css 编写代码:

http://codepen.io/anon/pen/EaQGvp

   <div class="slider"> 
    <input type="radio" id="control1" name="controls" checked="checked"/>
    <label for="control1"></label>
    <input type="radio" id="control2" name="controls"/>
    <label for="control2"></label>
    <input type="radio" id="control3" name="controls"/>
    <label for="control3"></label>
    <input type="radio" id="control4" name="controls"/>
    <label for="control4"></label>
 <div class="sliderinner">
        <ul>
            <li>
                <img src="http://i.imgur.com/aAExlOn.jpg" />

            </li>
            <li>
                <img src="http://i.imgur.com/aAExlOn.jpg" />

            </li>
            <li>
                <img src="http://i.imgur.com/aAExlOn.jpg" />

            </li>
            <li>
                <img src="http://i.imgur.com/aAExlOn.jpg" />

            </li>

        </ul>
    </div>
</div>

【问题讨论】:

    标签: css slider


    【解决方案1】:

    终于找到了出路:

    @keyframes round{   
      25%{opacity:1;}
      40%{opacity:0;}
    } 
    
    .auto{
      position:absolute;
      animation:round 16s infinite;
      opacity:0;
     }
    
    img:nth-child(4){animation-delay:0s;}
    img:nth-child(3){animation-delay:4s;}
    img:nth-child(2){animation-delay:8s;}
    img:nth-child(1){animation-delay:12s;}
    

    auto 类添加到您的图像并尝试一下。

    Let me know if you are looking for something else :)
    

    【讨论】:

      【解决方案2】:

      看看这个:

      Live demo

      input[type=radio]#control1:checked~.sliderinner>ul { -webkit-animation: test infinite 10s alternate;
        animation: test infinite 10s alternate; }
      .slider input[type=radio]#control2:checked~.sliderinner>ul { left: -100% }
      .slider input[type=radio]#control3:checked~.sliderinner>ul { left: -200% }
      .slider input[type=radio]#control4:checked~.sliderinner>ul { left: -300% }
      .slider input[type=radio]#control5:checked~.sliderinner>ul { left: -400% }
      
      @-webkit-keyframes test {
         0% {
            left: 0;
          }
      
          10% {
            left: -100%;
          }
      
          30% {
            left: -200%
          }
      
          90% {
            left: -300%;
          }
      
          100% {
            left: -400%;
          }
      }
      @keyframes test {
         0% {
            left: 0;
          }
      
          10% {
            left: -100%;
          }
      
          30% {
            left: -200%
          }
      
          90% {
            left: -300%;
          }
      
          100% {
            left: -400%;
          }
      }
      

      这不完整但可以更好,这只是使用key frames的CSS解决方案

      你可以按照我的例子,让它看起来更好,祝你好运

      【讨论】:

      • 很酷!是否有可能让幻灯片只走一条路并以某种方式重新开始?
      • 是的,你可以在关键帧中使用 from/to 这里是一个关于关键帧的很好的教程 css-tricks.com/snippets/css/keyframe-animation-syntax 如果这解决了你的问题,请接受这个(点击勾选),以便其他人可以从中学习未来
      猜你喜欢
      • 2013-10-08
      • 2017-10-28
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多