如何循环这个CSS滑块动画?

2023-12-24

我正在尝试创建一个 css 滑块,到目前为止我只成功地让它正确迭代一次。有没有办法让它无限循环而不改变最终结果?

<div class="slider">
<div class="slides">
<div class="slider-1"></div>
<div class="slider-2"></div>
<div class="slider-3"></div>
<div class="slider-4"></div>
</div>
</div>

Css

.slider{
  width:700px;
  height:300px;
  margin:50px auto;
  border:1px solid;
  overflow:hidden;
}
.slides{
  width:400%;
  height:100%;
  -webkit-animation:slide-1 2s linear 4s 1 forwards, slide-2 2s linear 8s 1 forwards, slide-3 2s linear 12s 1 forwards, slide-4 2s linear 16s 1 forwards;
  -moz-animation:slide-1 2s linear 4s 1 forwards, slide-2 2s linear 8s 1 forwards, slide-3 2s linear 12s 1 forwards, slide-4 2s linear 16s 1 forwards;
  animation:slide-1 2s linear 4s 1 forwards, slide-2 2s linear 8s 1 forwards, slide-3 2s linear 12s 1 forwards, slide-4 2s linear 16s 1 forwards;
}
.slider-1, .slider-2, .slider-3, .slider-4{
  width:25%;
  height:100%;
  float:left;
}
.slider-1{
  background:#222;
}
.slider-2{
  background:#444;
}
.slider-3{
  background:#666;
}
.slider-4{
  background:#888;
}

@-webkit-keyframes slide-1{
  from{margin-left:0px;}
  to{margin-left:-100%;}
}
@-webkit-keyframes slide-2{
  from{margin-left:-100%;}
  to{margin-left:-200%;}
}
@-webkit-keyframes slide-3{
  from{margin-left:-200%;}
  to{margin-left:-300%;}
}
@-webkit-keyframes slide-4{
  from{margin-left:-300%;}
  to{margin-left:0%;}
}
@-moz-keyframes slide-1{
  from{margin-left:0px;}
  to{margin-left:-100%;}
}
@-moz-keyframes slide-2{
  from{margin-left:-100%;}
  to{margin-left:-200%;}
}
@-moz-keyframes slide-3{
  from{margin-left:-200%;}
  to{margin-left:-300%;}
}
@-moz-keyframes slide-4{
  from{margin-left:-300%;}
  to{margin-left:0%;}
}
@keyframes slide-1{
  from{margin-left:0px;}
  to{margin-left:-100%;}
}
@keyframes slide-2{
  from{margin-left:-100%;}
  to{margin-left:-200%;}
}
@keyframes slide-3{
  from{margin-left:-200%;}
  to{margin-left:-300%;}
}
@keyframes slide-4{
  from{margin-left:-300%;}
  to{margin-left:0%;}
}

http://jsfiddle.net/1kcbpqfu/ http://jsfiddle.net/1kcbpqfu/


在我看来,这是最好的解决方案之一。

/* ANIMATION */
@keyframes cycle {
	0%  { top:0px; }
	4%  { top:0px; } 
	16% { top:0px; opacity:1; z-index:0; } 
	20% { top:325px; opacity:0; z-index:0; } 
	21% { top:-325px; opacity:0; z-index:-1; }
	92% { top:-325px; opacity:0; z-index:0; }
	96% { top:-325px; opacity:0; }
	100%{ top:0px; opacity:1; }
	
}
@keyframes cycletwo {
	0%  { top:-325px; opacity:0; }
	16% { top:-325px; opacity:0; }
	20% { top:0px; opacity:1; }
	24% { top:0px; opacity:1; } 
	36% { top:0px; opacity:1; z-index:0; } 
	40% { top:325px; opacity:0; z-index:0; }
	41% { top:-325px; opacity:0; z-index:-1; } 
	100%{ top:-325px; opacity:0; z-index:-1; }
}
@keyframes cyclethree {
	0%  { top:-325px; opacity:0; }
	36% { top:-325px; opacity:0; }
	40% { top:0px; opacity:1; }
	44% { top:0px; opacity:1; } 
	56% { top:0px; opacity:1; } 
	60% { top:325px; opacity:0; z-index:0; }
	61% { top:-325px; opacity:0; z-index:-1; } 
	100%{ top:-325px; opacity:0; z-index:-1; }
}
@keyframes cyclefour {
	0%  { top:-325px; opacity:0; }
	56% { top:-325px; opacity:0; }
	60% { top:0px; opacity:1; }
	64% { top:0px; opacity:1; }
	76% { top:0px; opacity:1; z-index:0; }
	80% { top:325px; opacity:0; z-index:0; }
	81% { top:-325px; opacity:0; z-index:-1; }
	100%{ top:-325px; opacity:0; z-index:-1; }
}
@keyframes cyclefive {
	0%  { top:-325px; opacity:0; }
	76% { top:-325px; opacity:0; }
	80% { top:0px; opacity:1; }
	84% { top:0px; opacity:1; }
	96% { top:0px; opacity:1; z-index:0; }
	100%{ top:325px; opacity:0; z-index:0; }
}

/* ANIMATION BAR */
@keyframes fullexpand {
    0%, 20%, 40%, 60%, 80%, 100% { width:0%; opacity:0; }
    4%, 24%, 44%, 64%, 84% { width:0%; opacity:0.3; }
   16%, 36%, 56%, 76%, 96% { width:100%; opacity:0.7; }
   17%, 37%, 57%, 77%, 97% { width:100%; opacity:0.3; }
   18%, 38%, 58%, 78%, 98% { width:100%; opacity:0; }	
}

/* Common */
html, body {
	background:#eaeaea url(../img/bg.png) repeat;
	font-size:12px;
	font-family:"Open Sans", serif;
	min-width:960px;
	margin:0;
	padding:0;
	color:#aaa;
}

.content h1 {
	font-size:48px;
	color:#000;
	text-shadow:0px 1px 1px #f4f4f4;
	text-align:center;
	padding:60px 0 30px;	
}

/* LAYOUT */
.container {
	margin:0 auto;
	overflow:hidden;
	width:960px;
}

/* CONTENT SLIDER */
#content-slider {
	width:100%;
	height:360px;
	margin:10px auto 0;
}
/* SLIDER */
#slider {
	background:#000;
	border:5px solid #eaeaea;
	box-shadow:1px 1px 5px rgba(0,0,0,0.7);
	height:320px;
	width:680px;
	margin:40px auto 0;
	overflow:visible;
	position:relative;
}
#mask {
	overflow:hidden;
	height:320px;
}
#slider ul {
	margin:0;
	padding:0;
	position:relative;
}
#slider li {
	width:680px;
	height:320px;
	position:absolute;
	top:-325px;
	list-style:none;
}

#slider li.firstanimation {
	-moz-animation:cycle 25s linear infinite;	
	-webkit-animation:cycle 25s linear infinite;		
}
#slider li.secondanimation {
	-moz-animation:cycletwo 25s linear infinite;
	-webkit-animation:cycletwo 25s linear infinite;		
}
#slider li.thirdanimation {
	-moz-animation:cyclethree 25s linear infinite;
	-webkit-animation:cyclethree 25s linear infinite;		
}
#slider li.fourthanimation {
	-moz-animation:cyclefour 25s linear infinite;
	-webkit-animation:cyclefour 25s linear infinite;		
}
#slider li.fifthanimation {
	-moz-animation:cyclefive 25s linear infinite;
	-webkit-animation:cyclefive 25s linear infinite;		
}

#slider .tooltip {
	background:rgba(0,0,0,0.7);
	width:300px;
	height:60px;
	position:relative;
	bottom:75px;
	left:-320px;
	-moz-transition:all 0.3s ease-in-out;
	-webkit-transition:all 0.3s ease-in-out;  
}
#slider .tooltip h1 {
	color:#fff;
	font-size:24px;
	font-weight:300;
	line-height:60px;
	padding:0 0 0 20px;
}
#slider li#first:hover .tooltip, 
#slider li#second:hover .tooltip, 
#slider li#third:hover .tooltip, 
#slider li#fourth:hover .tooltip, 
#slider li#fifth:hover .tooltip {
	left:0px;
}
#slider:hover li, 
#slider:hover .progress-bar {
	-moz-animation-play-state:paused;
	-webkit-animation-play-state:paused;
}

/* PROGRESS BAR */
.progress-bar { 
	position:relative;
	top:-5px;
	width:680px; 
	height:5px;
	background:#000;
	-moz-animation:fullexpand 25s ease-out infinite;
	-webkit-animation:fullexpand 25s ease-out infinite;
}
<div class="content">
	<h1>Pure CSS3 Cycle Slider</h1>
</div>

<div class="container">
	<div id="content-slider">
    	<div id="slider">
        	<div id="mask">
            <ul>
           	<li id="first" class="firstanimation">
            <a href="#">
            <img src="http://www.alessioatzeni.com/CSS3-Cycle-Image-Slider/images/img_1.jpg" alt="Cougar"/>
            </a>
            <div class="tooltip">
            <h1>Cougar</h1>
            </div>
            </li>

            <li id="second" class="secondanimation">
            <a href="#">
            <img src="http://www.alessioatzeni.com/CSS3-Cycle-Image-Slider/images/img_2.jpg" alt="Lions"/>
            </a>
            <div class="tooltip">
            <h1>Lions</h1>
            </div>
            </li>
            
            <li id="third" class="thirdanimation">
            <a href="#">
            <img src="http://www.alessioatzeni.com/CSS3-Cycle-Image-Slider/images/img_3.jpg" alt="Snowalker"/>
            </a>
            <div class="tooltip">
            <h1>Snowalker</h1>
            </div>
            </li>
                        
            <li id="fourth" class="fourthanimation">
            <a href="#">
            <img src="http://www.alessioatzeni.com/CSS3-Cycle-Image-Slider/images/img_4.jpg" alt="Howling"/>
            </a>
            <div class="tooltip">
            <h1>Howling</h1>
            </div>
            </li>
                        
            <li id="fifth" class="fifthanimation">
            <a href="#">
            <img src="http://www.alessioatzeni.com/CSS3-Cycle-Image-Slider/images/img_5.jpg" alt="Sunbathing"/>
            </a>
            <div class="tooltip">
            <h1>Sunbathing</h1>
            </div>
            </li>
            </ul>
            </div>
            <div class="progress-bar"></div>
        </div>
    </div>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何循环这个CSS滑块动画? 的相关文章

随机推荐

  • 如何使用 pyspark 读取字段中包含逗号的 CSV 文件? [复制]

    这个问题在这里已经有答案了 我有一个 csv 文件 其中列值中包含逗号 例如 Column1 Column2 Column3 123 45 6 789 当数据中包含额外的逗号时 这些值会用双引号引起来 在上面的示例中 值是 Column1
  • 有条件地指定 noexcept 函数

    假设我声明了这样的函数noexcept int pow int base int exp noexcept return exp 0 1 base pow base exp 1 从我很少但慢慢增长的 C 知识来看 我可以noexcept当我
  • 在 Stripe Connect 入门中设置电话号码字段的默认国家/地区?

    这是相当小的 但为了更好的用户体验 在 stripe connect 登录期间 我希望电话号码字段默认为连接用户的国家 地区 就像地址字段一样 我怎样才能做到这一点 请注意 我没有用户的电话号码 因此无法提供参数为Account creat
  • 如何处理 Shopify API 与 Shopify gem 的连接?

    您好 我正在我的 Shopify 应用中使用 Shopify gem 我正在寻找有关如何处理与 Shopify 的 API 连接的建议 我正在使用 webhooks 和delayed jobs 所以我需要一种方法来打开控制器外部的连接 目前
  • 为什么编译器说:“enable_if”不能用于禁用此声明

    template
  • imshow 的颜色条,以 0 为中心并带有符号刻度

    我想生成一个由多个数组组成的绘图网格 具有正值和负值 具有对数刻度 共享相同的颜色条 我已经实现了颜色条的共享部分 使用 ImageGrid 和常见的最大值和最小值 并且我知道在只有正值的情况下 我可以在 imshow 调用上使用 LogN
  • 无法设置 JFrame 的最大大小(Windows 下)

    我正在尝试限制 a 的最大尺寸JFrame 然而 这只适用于 Linux 在 Windows 下 JFrame可以自由调整大小 代码非常简单 public class TestMaxSize extends javax swing JFra
  • 媒体播放器、进度条

    这是播放媒体时更新进度条的正确方法吗 我以为MediaPlayer中会有回调 但我找不到它 mediaPlayer start final SeekBar progress SeekBar dialog findViewById R id
  • 如何获取进程列表

    我正在使用节点并将其安装在我的机器上 现在我想获取我的机器上运行的进程列表 以便我可以查看 Apache 是否正在运行 MySQL 是否已启动等 我怎样才能做到这一点 我的 js 文件中只有非常基本的代码 我什至不知道从哪里开始 这是我的代
  • Eslint 预期缩进 1 个制表符但发现 4 个空格错误

    我正在使用 VScode 和最新版本的 Eslint 这是我第一次使用 linter 使用制表符作为缩进时 我不断收到此 linting 错误 严重性 错误 message 预期缩进 1 个制表符 但发现有 4 个空格 缩进 在 4 5 来
  • Pytorch批量矩阵向量外积

    我正在尝试使用 PyTorch 生成向量矩阵外积 张量 假设向量v有尺寸p和矩阵M有尺寸qXr 乘积的结果应为 pXqXr Example size 2 v 0 1 size 2X3 M 0 1 2 3 4 5 size 2X2X3 v M
  • 使用画布的 3D 立方体。需要一点改进

    我使用以下代码制作了这个 3d 立方体 Matrix mMatrix canvas getMatrix canvas save camera save camera rotateY angle camera getMatrix mMatri
  • Python 字符串与字节数组之间的转换

    如何将人类可读的字符串转换为字节数组并返回 假设我有 Hello World 并且想要一个字节数组 然后从字节数组到相同的字符串 您可以使用bytearray https docs python org 2 library function
  • 将 collections.deque 转换为 python 列表的算法复杂度是多少?

    我试图确定将 collections deque 对象转换为 python 列表对象的复杂度是 O n 我想它必须获取每个元素并将其转换为列表 但我似乎找不到双端队列背后的实现代码 那么 Python 是否在幕后内置了一些更高效的东西 可以
  • nlp - 如何检测句子中的单词是否指向颜色/身体部位/车辆

    因此 正如标题所示 我想知道句子中的某个单词是否指向 1 一种颜色 The grass is green 因此 绿色 是颜色 2 身体的一部分 Her hands are soft 因此 手 是身体的一部分 3 车辆 I am drivin
  • 循环数据提取所有以 .co.uk 结尾的电子邮件地址

    我试图通过应对以下挑战来提高我的编程 PHP 技能 接下来的问题并不是关于代码问题 也不是我要求代码问题 而是关于应该应用的编程逻辑 9 email protected cdn cgi l email protection 0 0 1 1
  • 远程访问HDFS

    我有hadoop服务器在某些服务器上运行 比如说IP 192 168 11 7 其 core site xml 如下
  • DataTable 服务器端仅在我有少量数据时才工作

    我正在从 json 加载传递到有关数据表表的服务器端处理 我有两种环境 一种用于测试 一种用于生产 它们具有相同的功能和数据库结构 当我在测试环境中测试新进程时 脚本加载数据没有任何问题 5行 相同的脚本不会在生产环境中加载数据 1200
  • 使用opencv读取带有type_id opencv-image的xml文件

    嘿 我在读取 type id opencv image 的 xml 文件时尝试了很多搜索 我在这里查找的只是 opencv matrix 所有可用的帮助对我来说都是无用的 请帮我从 xml 文件中读取图像矩阵 我将 xml 文件的上半部分粘
  • 如何循环这个CSS滑块动画?

    我正在尝试创建一个 css 滑块 到目前为止我只成功地让它正确迭代一次 有没有办法让它无限循环而不改变最终结果 div class slider div class slides div class slider 1 div div cla