html载入动画怎么设置,「HTML+CSS」--自定义加载动画【007】

Part1作者简介昵称:海轰

标签:程序猿一只|C++选手|学生

简介:因C语言结识编程,随后转入计算机专业,有幸拿过国奖、省奖等,已保研。目前正在学习C++/Linux(真的真的太难了~)

学习经验:扎实基础 + 多做笔记 + 多敲代码 + 多思考 + 学好英语!

Part2效果展示format,png

Part3Demo代码

HTMLhtml>

Document

CSShtml,body{

margin: 0;

height: 100%;

}

body{

display: flex;

justify-content: center;

align-items: center;

background: #263238;

}

section {

width: 650px;

height: 300px;

padding: 10px;

position: relative;

display: flex;

align-items: center;

justify-content: center;

/* 红色边框仅作提示 */

border: 2px solid red;

}

span{

width: 96px;

height: 96px;

border: 10px solid transparent;

border-radius: 50%;

display: flex;

align-items: center;

justify-content: center;

position: relative;

border-bottom-color: #FF3D00;

animation: rotation 1s linear infinite;

}

span::after{

position: relative;

content: '';

display: inline-block;

width:  72px;

height:  72px;

border-radius: 50%;

border: 10px solid transparent;

border: 10px solid #fff;

}

@keyframes rotation {

0% { transform: rotate(0deg) }

100% { transform: rotate(360deg)

}

}

Part4原理解释

动画的核心部分就是span和span::after,section仅作为提示框。

步骤1

将span元素设置为一个96✖️96px的正方形

边框为10px,白色,solidwidth : 96px;

height: 96px;

border: 10px solid #fff;

效果图如下format,png

步骤2

span::after伪元素设置为:位于span正中

边长72✖️72px的正方形

注:红色部分即为span::after,为便于观察才设置为红色format,png

步骤3

span::after设置边框:10px 白色 solidborder: 10px solid white;

注:此时的span::after变成了变成(72+10+10)px 的正方形format,png

步骤4

设置span下边框颜色设置为红色border-bottom-color: red;

效果图如下format,png

步骤5

span和span::after圆角设置:50%border-radius: 50%;

效果图如下format,png

步骤6

span四边框颜色为透明border: 10px solid transparent;

注因为border-bottom-color: #FF3D00;声明了下边框颜色为红色,所以下边框依然会显示颜色format,png

步骤7

为span添加动画animation: rotation 1s linear infinite;/*动画实现*/

@keyframes rotation {

0% { transform: rotate(0deg) }

100% { transform: rotate(360deg)

}

效果图如下format,png

Part5结语

学习来源:https://codepen.io/bhadupranjal/pen/vYLZYqQ

文章仅作为学习笔记,记录从0到1的一个过程。

希望对您有所帮助,如有错误欢迎小伙伴指正~

Part6系列文章format,png「HTML+CSS」--自定义加载动画【006】format,png「HTML+CSS」--自定义加载动画【005】format,png「HTML+CSS」--自定义按钮样式【004】format,png「HTML+CSS」--自定义按钮样式【003】format,png「HTML+CSS」--自定义按钮样式【002】

我是海轰ଘ(੭ˊᵕˋ)੭,如果您觉得写得可以的话,请点个赞吧

谢谢支持❤️format,png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值