Problem with running CSS animation

Asked

Viewed 36 times

0

I made an animation in CSS, but it stopped working. Where is the error?

HTML/CSS

#loading {
	background-color: #0e5077;
	height: 100%;
	width: 100%;
	position: fixed;
	z-index: 99;
	margin-top: 0px;
	top: 0px;
}

#loading-center {
	width: 100%;
	height: 100%;
	position: relative;
}
#loading-center-absolute {
	position: absolute;
	left: 50%;
	top: 50%;
	height: 100px;
	width: 100px;
	margin-top: -50px;
	margin-left: -50px;
	-ms-transform: rotate(-135deg);
	-webkit-transform: rotate(-135deg);
	transform: rotate(-135deg);
}
#object_one {
	left: 55px;
	top: 55px;
	width: 10px;
	height: 10px;
}
#object_two {
	left: 45px;
	top: 45px;
	width: 30px;
	height: 30px;
	-webkit-animation-delay: 0.2s;
	animation-delay: 0.2s;
}
#object_three {
	left: 35px;
	top: 35px;
	width: 50px;
	height: 50px;
	-webkit-animation-delay: 0.4s;
	animation-delay: 0.4s;
}
#object_four {
	left: 25px;
	top: 25px;
	width: 70px;
	height: 70px;
	-webkit-animation-delay: 0.6s;
	animation-delay: 0.6s;
}
.object {
	-moz-border-radius: 50% 50% 50% 50%;
	-webkit-border-radius: 50% 50% 50% 50%;
	border-radius: 50% 50% 50% 50%;
	position: absolute;
	border-top: 2px solid #FFF;
	border-bottom: 2px solid transparent;
	border-left: 2px solid #FFF;
	border-right: 2px solid transparent;
	-webkit-animation: animate 2s infinite;
	animation: animate 2s infinite;
}
<div id="loading">
	<div id="loading-center-absolute">
                <div class="object" id="object_one"></div>
                <div class="object" id="object_two"></div>
                <div class="object" id="object_three"></div>
                <div class="object" id="object_four"></div>
            </div>
</div>

  • But you didn’t have to have one keyframes there is no??

  • Jeez, it’s true, I was moving to another page and ended up not copying that part of the code. My lack of attention.

2 answers

1

I believe you forgot to add the "@keyframes" rule to run your animation, as I did below. For linear execution, without breaks between the beginning and the end of the animation, add "linear" to the property "Animation".

#loading {
	background-color: #0e5077;
	height: 100%;
	width: 100%;
	position: fixed;
	z-index: 99;
	margin-top: 0px;
	top: 0px;
}

#loading-center {
	width: 100%;
	height: 100%;
	position: relative;
}
#loading-center-absolute {
	position: absolute;
	left: 50%;
	top: 50%;
	height: 100px;
	width: 100px;
	margin-top: -50px;
	margin-left: -50px;
	-ms-transform: rotate(-135deg);
	-webkit-transform: rotate(-135deg);
	transform: rotate(-135deg);
}
#object_one {
	left: 55px;
	top: 55px;
	width: 10px;
	height: 10px;
}
#object_two {
	left: 45px;
	top: 45px;
	width: 30px;
	height: 30px;
	-webkit-animation-delay: 0.2s;
	animation-delay: 0.2s;
}
#object_three {
	left: 35px;
	top: 35px;
	width: 50px;
	height: 50px;
	-webkit-animation-delay: 0.4s;
	animation-delay: 0.4s;
}
#object_four {
	left: 25px;
	top: 25px;
	width: 70px;
	height: 70px;
	-webkit-animation-delay: 0.6s;
	animation-delay: 0.6s;
}
.object {
	-moz-border-radius: 50% 50% 50% 50%;
	-webkit-border-radius: 50% 50% 50% 50%;
	border-radius: 50% 50% 50% 50%;
	position: absolute;
	border-top: 2px solid #FFF;
	border-bottom: 2px solid transparent;
	border-left: 2px solid #FFF;
	border-right: 2px solid transparent;
	-webkit-animation: animate 2s linear infinite;
	animation: animate 2s linear infinite;
}

@keyframes animate {
	from {
	    transform: rotate(0deg)
	}
	to {
	    transform: rotate(360deg)
	}
}
<div id="loading">
	<div id="loading-center-absolute">
                <div class="object" id="object_one"></div>
                <div class="object" id="object_two"></div>
                <div class="object" id="object_three"></div>
                <div class="object" id="object_four"></div>
            </div>
</div>

1

#loading {
	background-color: #0e5077;
	height: 100%;
	width: 100%;
	position: fixed;
	z-index: 99;
	margin-top: 0px;
	top: 0px;
}

#loading-center {
	width: 100%;
	height: 100%;
	position: relative;
}
#loading-center-absolute {
	position: absolute;
	left: 50%;
	top: 50%;
	height: 100px;
	width: 100px;
	margin-top: -50px;
	margin-left: -50px;
	-ms-transform: rotate(-135deg);
	-webkit-transform: rotate(-135deg);
	transform: rotate(-135deg);
}
#object_one {
	left: 55px;
	top: 55px;
	width: 10px;
	height: 10px;
}
#object_two {
	left: 45px;
	top: 45px;
	width: 30px;
	height: 30px;
	-webkit-animation-delay: 0.2s;
	animation-delay: 0.2s;
}
#object_three {
	left: 35px;
	top: 35px;
	width: 50px;
	height: 50px;
	-webkit-animation-delay: 0.4s;
	animation-delay: 0.4s;
}
#object_four {
	left: 25px;
	top: 25px;
	width: 70px;
	height: 70px;
	-webkit-animation-delay: 0.6s;
	animation-delay: 0.6s;
}
.object {
	-moz-border-radius: 50% 50% 50% 50%;
	-webkit-border-radius: 50% 50% 50% 50%;
	border-radius: 50% 50% 50% 50%;
	position: absolute;
	border-top: 2px solid #FFF;
	border-bottom: 2px solid transparent;
	border-left: 2px solid #FFF;
	border-right: 2px solid transparent;
	-webkit-animation: rotation 2s infinite linear;
	animation: rotation 2s infinite linear;
}

@-webkit-keyframes rotation {
		from {
				-webkit-transform: rotate(0deg);
		}
		to {
				-webkit-transform: rotate(359deg);
		}
}
<div id="loading">
	<div id="loading-center-absolute">
                <div class="object" id="object_one"></div>
                <div class="object" id="object_two"></div>
                <div class="object" id="object_three"></div>
                <div class="object" id="object_four"></div>
            </div>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.