首页 文章详情

【动画消消乐】HTML+CSS 自定义加载动画 057

海轰Pro | 142 2021-06-07 00:25 0 0 0
UniSMS (合一短信)

效果展示

Demo代码

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Document</title>
</head>
<body>
    <section><span></span></section>
</body>
</html>

CSS

htmlbody {
  margin0;
  height100%;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  background#ed556a;
}

section {
  width650px;
  height300px;
  padding10px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border2px solid white;
}

span {
  width48px;
  height48px;
  display: inline-block;
  position: relative;
  background: white;
  animation: loading 3s linear infinite;
}

@keyframes loading {
/*先x轴翻转180度 后y轴翻转180度*/
  0% {
    transformperspective(200pxrotateX(0degrotateY(0deg);
  }
  50% {
    transformperspective(200pxrotateX(-180degrotateY(0deg);
  }
  100% {
    transformperspective(200pxrotateX(-180degrotateY(-180deg)
  }
}

原理详解

步骤1

使用span标签,设置为

  • 宽度、高度均为48px
  • 背景色:白色
  width: 48px;
height: 48px;
background: white;

效果图如下

步骤2

为span添加动画

  • 先绕x轴翻转180度
  • 后绕y轴翻转180度
@keyframes loading {
/*先x轴翻转180度 后y轴翻转180度*/
0% {
transform: perspective(200px) rotateX(0deg) rotateY(0deg);
}
50% {
transform: perspective(200px) rotateX(-180deg) rotateY(0deg);
}
100% {
transform: perspective(200px) rotateX(-180deg) rotateY(-180deg)
}
}

效果图如下

结语

希望对您有所帮助

如有错误欢迎小伙伴指正~

我是 海轰ଘ(੭ˊᵕˋ)੭

如果您觉得写得可以的话

请点个赞吧

谢谢支持❤️


good-icon 0
favorite-icon 0
收藏
回复数量: 0
    暂无评论~~
    Ctrl+Enter