- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我只是想反转我的纯 css 水平图像 slider 滑动的方向。我尝试以相反的方向改变关键帧动画部分,同时使用 -
位置并将 left
切换到 right
,我所有的尝试都是允许的一张幻灯片以正确的方向滑动,然后由于我的图像 float: left;
现场直播jsFiddle . 而这是一个Jsfiddle我的尝试及其渲染方式(即。 不工作。它以正确的方向滑过一个图像,但不是其余的)
此外,我的代码如下。
标记:
<div class="slider3">
<figure>
<img src="http://img00.deviantart.net/a251/i/2007/347/c/8/drunk_santa_by_yakuks.png">
<img src="http://img00.deviantart.net/a251/i/2007/347/c/8/drunk_santa_by_yakuks.png">
<img src="http://img00.deviantart.net/a251/i/2007/347/c/8/drunk_santa_by_yakuks.png">
<img src="http://img00.deviantart.net/a251/i/2007/347/c/8/drunk_santa_by_yakuks.png">
</figure>
</div>
CSS:
.slider3 {
width: 100%;
max-width: 960px;
overflow: hidden;
}
.slider3 figure img {
width: 25%;
float: left;
background: red;
}
.slider3 figure{
width: 400%;
position: relative;
margin:0;
padding: 0;
animation: 10s slide infinite;
-webkit-animation: 10s slide infinite;
}
@-webkit-keyframes slide {
0% { left:0%; }
16% { left:0%; }
33% { left:-100%; }
49% { left:-100%; }
66% { left:-200%; }
82% { left:-200%; }
100% { left:-300%; }
}
最佳答案
实际上,除了添加 animation-direction: reverse
之外,您无需进行任何修改。到规则列表(或者您可以将其设置为 animation
速记中的值)。正如您所猜到的,添加这个属性值对会反转动画的流程。
当您在页面上放置 4 张图片(float: left
,每张图片的宽度为 100%)时,第一张图片为 0%,第二张为 100%,第三张为 200%,第四张为 300%。您当前的动画所做的是 - 从 left: 0%
开始这意味着第一张图片在 View 中。一段时间后 left
offset 设置为 -100%,这意味着页面上 100% 的第二张图像现在将显示(100% - 100% = 0%,因此它落在查看区域中)。同样,第 3 和第 4 也会显示。
现在要反转动画,您需要 left
偏移量从 -300% 开始,这样第四张图像首先可见,然后向右滑动而不是向左滑动。 注意:如果您希望 DOM 中的第一张图像首先显示,请更改 float:left
至 right
对于 .slider3 figure img
.
DOM 中的第四张图片首先出现: ( float: left
)
.slider3 {
width: 100%;
max-width: 960px;
overflow: hidden;
}
.slider3 figure img {
width: 25%;
float: left;
background: red;
}
.slider3 figure {
width: 400%;
position: relative;
margin: 0;
padding: 0;
animation: 10s slide infinite reverse backwards;
-webkit-animation: 10s slide infinite reverse backwards;
}
@-webkit-keyframes slide {
0% {
left: 0%;
}
16% {
left: 0%;
}
33% {
left: -100%;
}
49% {
left: -100%;
}
66% {
left: -200%;
}
82% {
left: -200%;
}
100% {
left: -300%;
}
}
@keyframes slide {
0% {
left: 0%;
}
16% {
left: 0%;
}
33% {
left: -100%;
}
49% {
left: -100%;
}
66% {
left: -200%;
}
82% {
left: -200%;
}
100% {
left: -300%;
}
}
<div class="slider3">
<figure>
<img src="http://lorempixel.com/200/200/nature/1">
<img src="http://lorempixel.com/200/200/nature/2">
<img src="http://lorempixel.com/200/200/nature/3">
<img src="http://lorempixel.com/200/200/nature/4">
</figure>
</div>
首先出现 DOM 中的第一张图像: ( float: right
)
.slider3 {
width: 100%;
max-width: 960px;
overflow: hidden;
}
.slider3 figure img {
width: 25%;
float: right;
background: red;
}
.slider3 figure {
width: 400%;
position: relative;
margin: 0;
padding: 0;
animation: 10s slide infinite reverse backwards;
-webkit-animation: 10s slide infinite reverse backwards;
}
@-webkit-keyframes slide {
0% {
left: 0%;
}
16% {
left: 0%;
}
33% {
left: -100%;
}
49% {
left: -100%;
}
66% {
left: -200%;
}
82% {
left: -200%;
}
100% {
left: -300%;
}
}
@keyframes slide {
0% {
left: 0%;
}
16% {
left: 0%;
}
33% {
left: -100%;
}
49% {
left: -100%;
}
66% {
left: -200%;
}
82% {
left: -200%;
}
100% {
left: -300%;
}
}
<div class="slider3">
<figure>
<img src="http://lorempixel.com/200/200/nature/1">
<img src="http://lorempixel.com/200/200/nature/2">
<img src="http://lorempixel.com/200/200/nature/3">
<img src="http://lorempixel.com/200/200/nature/4">
</figure>
</div>
您会注意到我添加了一个 backwards
也给animation
速记属性(property)。这代表 animation-fill-mode
它使元素保持其最后一个关键帧的状态,直到动画开始为止。如果未添加此选项,则在开始时将显示第一张图片,然后立即使用 float:left
更改为第四张(无幻灯片)。反之亦然 float: right
.
Amr Aly 的第二个答案会奏效(还有其他可能的方法),但绝对没有理由让它变得如此复杂。
关于css - 纯CSS水平图像 slider 的反向关键帧方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40922991/
是否有一个 FFMPEG 命令,如果我们传递一个视频文件,在每个场景更改时它都应该为它生成一个关键帧。我理解的关键帧是视频的一系列文件(图像或视频)文件,可用于在视频悬停时播放。请让我们知道我们是否可
我正在切换我通过带有 JQuery 的 toggleClass 触发的一系列动画/过渡。 其中一个动画正在使用以下内容: .header { transition: all .3s ease-
我有一些图片可以在关键帧中很好地滚动 @-webkit-keyframes headImage /* Safari and Chrome */ { 0% {background:url(../imag
尝试用 jQuery 制作一个简单的重复关键帧动画 $(document).ready(function() { $('body').mouseover(function() {
我在 richard bradshaw 找到了一个关于 css3 transitions 的很好的教程,可以在 http://css3.bradshawenterprises.com/cfimg/ 我
我正在尝试使用@keyframes 为背景交换设置动画。背景是径向渐变。背景发生变化,但不是动画。 #mydiv { background: radial-gradient(circle at 90%
如果单击按钮 2,您将看到动画运行。但是,当我使用另一个功能对按钮进行更改(选中复选框以显示。隐藏按钮)时,动画会再次运行,就像再次按下一样。 如何防止每次单独的函数对按钮进行更改时触发动画?即在切换
所以我创建了图像生成器(生成 RGB 的非常简单的一个)我希望能够将一定数量的图像转换为 H264 关键帧+相关帧(lats 说 100)所以在生成的每 100 帧上我需要将它们编码为 H264 .怎
我一直在尝试自学一些带有关键帧的 css 动画,我正在尝试创建一些东西,其中有一个小方 block 落下,然后从那个方 block 中,一个矩形从左边突出,然后显示一些大约 8 秒后发短信,然后 re
我意识到我不能简单地通过用逗号分隔@keyframes mymove、@-moz-keyframes mymove 等来完成下面相同的代码。。为了让它们工作,我需要如下分别声明它们。 有什么方法可以将
恐怕有类似的问题,但我没有找到具体的解决方案,所以我创建了一个 fiddle : http://jsfiddle.net/Garavani/yrnjaf69/2/ TEXT
我有一个包含多个坐标的图像映射。但是,当我在上面放置一个关键帧 div (clouds) 时,这个不起作用,因为动画覆盖了 map 。最后一个 div 是一个动画,有一些云从图像上掠过。 html代码
所以我正在尝试为元素创建 Wifi 闪烁效果。首先圆圈应该是可见的,然后是上面的圆圈,依此类推。在所有符号都可见后,它应该等待 2 秒,然后重新开始。你可以在这里看到我的当前状态: http://js
我试图在单击按钮时显示一条消息。我想要“GO!”淡入/淡出表示游戏开始,但只有在单击开始按钮时才会出现。我现在正在尝试使用 jquery 和另一个来自老师的库的 javascript,它结合了鼠标点击
我正在尝试使用以下代码让对象在背景中从左向右浮动。不幸的是,当它离开屏幕时,尽管向类添加了 overflow-y: hidden 属性,但仍会出现垂直滚动条。我尝试了百分比(100% 与过渡)但它没有
我正在为将鼠标悬停在图形图像上时的弹跳效果创建关键帧。我的一切都正常工作,但是一旦动画完成..图标就会消失。 我知道它与电子邮件中设置的 translateY 属性有关,并在类里面链接。 在悬停时,我
你好我正在尝试模拟翻转倒数计时器但是当我编写代码时我发现两者之间存在差异: @keyframes zindex { 0% { z-index: 2; } 5% { z-index: 4
如果我有: @keyframes animateleft{from{left:-300px;opacity:0} to{left:0;opacity:1}} 是否可以: @keyframes anim
我有一个弹出窗口,它在单击按钮时打开,然后在您单击另一个按钮或弹出窗口之外时关闭。我希望弹出窗口在打开时淡入并在关闭时淡出。如何使用 javascript 在两个关键帧之间切换? 我尝试通过使用 ja
我正在尝试使用 jquery Keyframes用于动态创建的关键帧动画。我的页面上有六个图标(可能更多),它们都需要设置为以下范围内的随机 x 和 y 值的动画: x = 1-5y = 13-20
我是一名优秀的程序员,十分优秀!