html定义动画,「HTML+CSS」--自定义加载动画【016】

效果展示

06ab4a7aacc8ad6e6af008e5ec124a10.pngDemo代码

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 white;

border-style: solid  solid dotted dotted ;

border-radius: 50%;

position: relative;

display: flex;

align-items: center;

justify-content: center;

animation: rotation 2s linear infinite;

}

span::before{

position: relative;

content: '';

width:  48px;

height:  48px;

border: 10px  red solid;

border-style: solid  solid  dotted ;

border-radius: 50%;

/* 注意这里的时间 */

animation: rotationback 1s linear infinite;

}

@keyframes rotation {

0% { transform: rotate(0deg) }

100% { transform: rotate(360deg)

}

}

@keyframes rotationback {

0% { transform: rotate(360deg) }

100% { transform: rotate(0deg)

}

}原理详解

步骤1

使用span标签作为外围白色部分,并设置宽度、高度均为96px

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

height: 96px;

border: 10px solid white;

效果图如下

6c4195ee0b69eb2d00c80737a3813c1f.png

步骤2

设置span边框上/右边框为solid

下/左边框为dotter(点状)border-style: solid  solid dotted dotted ;

效果图如下

667f23f067ea35e75126ed15007f94ed.png

步骤3

使用span::before作为红色部分,并设置相对定位

宽度、高度均为48px

边框:10px 红色 solid

位于白色正方形 正中间(这里使用的是:在span中使用flex布局)width:  48px;

height:  48px;

border: 10px  red solid;

效果图如下

be3e2490765d4fa7888ba55352490dc2.png

步骤4

设置span::before边框下边框为dotted

其余为solidborder-style: solid  solid  dotted ;

效果图如下

7270d2bfb5fc19af5d72fbcfcdedee6e.png

步骤5

span、span::before圆角化border-radius: 50%;

效果图如下

06aef73de9708209323096982c5aa543.png

步骤6

为span添加动画顺时针 2s 无限循环animation: rotation 2s linear infinite;/*动画实现*/

@keyframes rotation {

0% { transform: rotate(0deg) }

100% { transform: rotate(360deg)

}

}

效果图如下

368e71a8d5c871033c1d7e31e8b5436d.png

步骤7

为span::before设置动画

-逆时针 1s 无限循环/*注意时间*/

animation: rotationback 1s linear infinite;/*动画实现*/

@keyframes rotationback {

0% { transform: rotate(360deg) }

100% { transform: rotate(0deg)

}

}

效果图如下

06ab4a7aacc8ad6e6af008e5ec124a10.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值