尝试显示6张幻灯片时,css中的滑块无法正常工作

时间:2018-04-26 15:42:51

标签: html css css3 slider

我正在尝试从我找到的codepen中调整一支笔,但它似乎不起作用。笔是一个带有3个幻灯片的文本滑块,我的目标是使其与6个幻灯片一起使用。
原始的代码是this
我的笔是this

我认为问题在于我的代码中错误百分比。我的6张幻灯片的代码是

@keyframes anim-1 {
0%,
4.15% {
    left: -100%;
    opacity: 0;
}
4.15%,
12.45% {
    left: 25%;
    opacity: 1;
}
16.66%,
100% {
    left: 110%;
    opacity: 0;
}
}

@keyframes anim-2 {
0%,
16.66% {
    left: -100%;
    opacity: 0;
}
20.75%,
29.17% {
    left: 25%;
    opacity: 1;
}
33.32%,
100% {
    left: 110%;
    opacity: 0;
}
}

@keyframes anim-3 {
0%,
33.32% {
    left: -100%;
    opacity: 0;
}
37.47%,
45.83% {
    left: 25%;
    opacity: 1;
}
49.98%,
100% {
    left: 110%;
    opacity: 0;
}
}

@keyframes anim-4 {
 0%,
49.98% {
    left: -100%;
    opacity: 0;
}
54.13%,
62.43% {
    left: 25%;
    opacity: 1;
}
66.58%,
100% {
    left: 110%;
    opacity: 0;
}
}

@keyframes anim-5 {
0%,
66.58% {
    left: -100%;
    opacity: 0;
}
70.73%,
79.03% {
    left: 25%;
    opacity: 1;
}
83.18%,
100% {
    left: 110%;
    opacity: 0;
}
}

@keyframes anim-6 {
 0%,
83.18% {
    left: -100%;
    opacity: 0;
}
87.33%,
95.85% {
    left: 25%;
    opacity: 1;
}
100% {
    left: 110%;
    opacity: 0;
}
}

我在这篇文章中弄乱了这里的缩进,但是在codepen中一切都应该更加清晰。
我不认为我犯了任何错别字,我仍在思考可能导致这种情况的原因。

1 个答案:

答案 0 :(得分:2)

在CSS中,您不是用逗号分隔不同的类。添加这些,它将起作用。

您的代码

.item-1, 
.item-2, 
.item-3
.item-4
.item-5
.item-6 {
...

修复

.item-1, 
.item-2, 
.item-3,
.item-4,
.item-5,
.item-6 {
...

@import url(https://fonts.googleapis.com/css?family=Open+Sans:600);

body { 
  font-family: 'Open Sans', 'sans-serif';
  color: #cecece;
  background: #222;
  overflow: hidden;
}

.item-1, 
.item-2, 
.item-3,
.item-4,
.item-5,
.item-6{
	position: absolute;
  display: block;
	top: 2em;
  
  width: 60%;
  
  font-size: 2em;

	animation-duration: 20s;
	animation-timing-function: ease-in-out;
	animation-iteration-count: infinite;
}

.item-1{
	animation-name: anim-1;
}

.item-2{
	animation-name: anim-2;
}

.item-3{
	animation-name: anim-3;
}

.item-4{
	animation-name: anim-4;
}

.item-5{
	animation-name: anim-5;
}

.item-6{
	animation-name: anim-6;
}

@keyframes anim-1 {
	0%, 4.15% { left: -100%; opacity: 0; }
  4.15%, 12.45% { left: 25%; opacity: 1; }
  16.66%, 100% { left: 110%; opacity: 0; }
}

@keyframes anim-2 {
	0%, 16.66% { left: -100%; opacity: 0; }
  20.75%, 29.17% { left: 25%; opacity: 1; }
  33.32%, 100% { left: 110%; opacity: 0; }
}

@keyframes anim-3 {
	0%, 33.32% { left: -100%; opacity: 0; }
  37.47%, 45.83% { left: 25%; opacity: 1; }
  49.98%, 100% { left: 110%; opacity: 0; }
}

@keyframes anim-4 {
	0%, 49.98% { left: -100%; opacity: 0; }
  54.13%, 62.43% { left: 25%; opacity: 1; }
  66.58%, 100% { left: 110%; opacity: 0; }
}

@keyframes anim-5 {
	0%, 66.58% { left: -100%; opacity: 0; }
  70.73%, 79.03% { left: 25%; opacity: 1; }
  83.18%, 100% { left: 110%; opacity: 0; }
}

@keyframes anim-6 {
	0%, 83.18% { left: -100%; opacity: 0; }
  87.33%, 95.85% { left: 25%; opacity: 1; }
  100% { left: 110%; opacity: 0; }
}
<p class="item-1">This is your last chance. After this, there is no turning back.</p>

<p class="item-2">You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe.</p>

<p class="item-3">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>

<p class="item-4">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>

<p class="item-5">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>

<p class="item-6">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>

<强> JSFiddle