<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>纯CSS实现的篮球动画</title>
<style>
/* used flexbox to center content */
body {
height: 100%;
padding: 0;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
}
#basket img {
display: block;
position: absolute;
top: 55px;
left: 20px;
min-width: 228px;
height: 193px;
}
/* wrapper for 800x600 screen */
#allWrapper {
position: relative;
width: 800px;
height: 600px;
background: url("images/5Y.svg");
background-size: cover;
z-index: -5;
}
/* animation container */
#ballWrapper {
width: 100px;
height: 260px;
display: block;
position: absolute;
cursor: pointer;
left: 47%;
top: 35%;
}
#ball {
width: 70px;
height: 70px;
position: relative;
animation: jump 1s infinite;
overflow: hidden;
}
/*Ball texture*/
#ball:after {
content: "";
width: 70px;
height: 70px;
border-radius: 100%;
background: url("images/4D.svg");
position: absolute;
animation: rotate 2s infinite, back 1s infinite;
z-index: 5;
background-repeat: repeat;
background-size: cover;
animation-timing-function: linear;
}
/*Ball light*/
#ball:before {
content: "";
position: absolute;
width: 100%;
height: 100%;
z-index: 10;
background-image: url("images/5C.svg");
background-size: 110%;
border-radius: 100%;
animation: lightop 1s infinite;
}
/*Shadow on ball*/
#ballshad {
background: url("images/5P.svg");
width: 100%;
height: 100%;
position: absolute;
border-radius: 100%;
animation: shadop 1s infinite;
margin: auto;
display: block;
background-size: contain;
z-index: 10;
}
/*Shadow on floor*/
#ballShadow {
position: absolute;
left: 50%;
bottom: 0;
z-index: 10;
margin-left: -30px;
background-image: url("images/4V.svg");
background-size: cover;
background-repeat: no-repeat;
border-radius: 100%;
animation: shrink 1s infinite;
z-index: -1;
background-position: center;
}
/* Animation keyframes */
@keyframes jump {
0% {
top: 0;
transform: scale3d(1, 1, 1);
border-radius: 100%;
animation-timing-function: ease-in;
}
45% {
transform: scale3d(1, 1, 1);
}
50% {
top: 200px;
animation-timing-function: ease-out;
transform: scale3d(1.3, .8, 1);
}
55% {
transform: scale3d(1, 1, 1);
}
60% {
transform: scale3d(.8, 1.1, 1);
}
70% {
transform: scale3d(.95, 1.05, 1);
}
72% {
transform: scale3d(1, 1, 1);
}
100% {
transform: scale3d(1, 1, 1);
top: 0;
border-radius: 100%;
}
}
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@keyframes shrink {
0% {
bottom: 0;
margin-left: -30px;
width: 80px;
height: 20px;
animation-timing-function: ease-in;
left: 150%;
opacity: .2;
}
50% {
bottom: 5px;
margin-left: -10px;
width: 50px;
height: 10px;
animation-timing-function: ease-out;
left: 35%;
opacity: 1;
}
100% {
bottom: 0;
margin-left: -30px;
width: 80px;
height: 20px;
animation-timing-function: ease-in;
left: 150%;
opacity: .2;
}
}
@keyframes lightop {
0% {
opacity: .25;
}
50% {
opacity: .1;
}
100% {
opacity: .25;
}
}
@keyframes shadop {
0% {
opacity: .25;
}
50% {
opacity: .55;
}
100% {
opacity: .25;
}
}
@keyframes back {
0% {
background-position: top;
}
100% {
background-position: bottom;
}
}
</style>
</head>
<body>
<div id="allWrapper">
<div id="basket"><img src="images/4N.svg" alt="" />
</div>
<div id="ballWrapper">
<div id="ball"><span id="ballshad"></span>
</div>
<div id="ballShadow"></div>
</div>
</div>
</body>
</html>