圆弧和扇形的加载动画该怎么写?


本文摘自PHP中文网,作者PHP中文网,侵删。

0.静态效果图

1.画弧度的代码

1

2

3

4

5

width: 3em;

height: 3em;

border: 7px transparent solid;

border-left: 7px #4DB6AC solid;

border-radius: 50%;

  

* 这里还有另一个方式

1

2

3

4

border-left:7px #4DB6AC solid

border-radius: 50%;

border-top:7px transparent solid;

border-bottom:7px transparent solid;

  后者做成旋转动画效果不如前者,肉眼能感到差异,在chrome49.

2.画扇形的代码

1

2

3

border: 7px transparent solid;

border-left: 7px #4DB6AC solid;

border-radius: 50%;

  

* 画扇形不可以定义宽度和长度,其余与画圆弧相同

3.less 封装画圆弧和扇形的代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

.arc(@direction,@style){

@color:~`"@{style}".split(/,\s+/)[1]`;

@width:~`"@{style}".split(/,\s+/)[0].replace("[","")`;

@shape:~`"@{style}".split(/,\s+/)[2].replace("]","")`;

border: @width transparent @shape;

@length:length(@direction);

.setStyle(@length,@style,@direction);

border-radius: 50%;

 

.setStyle(@length,@style,@direction) when (@length>0){

@index:@length - 1;

@pos:extract(@direction,@length);

border-@{pos}:@style ;

.setStyle(@index,@style,@direction);

 

}

}

//使用方式:

@driection 可以是top、left、right、bottom中的一个或多个

@style 需要严格按照 7px solid red 这样的顺序

.arc(left,7px solid red);

.arc(left top,7px solid red);

View Code

4.加载动画的完整代码

1

2

3

4

5

6

7

8

9

10

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><style> html,body {  overflow: hidden;  width: 100%;  height: 100%;}.container {  display: -webkit-box;  display: -ms-flexbox;  display: flex;  -ms-flex-wrap: wrap;  flex-wrap: wrap;  -webkit-box-pack: space-around;  -ms-flex-pack: space-around;  justify-content: space-around;  margin: 0 auto;  max-width: 650px;  min-width: 200px;}.container .canvas {  -webkit-box-align: center;  -ms-flex-align: center;  align-items: center;  display: -webkit-box;  display: -ms-flexbox;  display: flex;  -webkit-box-pack: center;  -ms-flex-pack: center;  justify-content: center;  background: #eee;  border-radius: 50%;  -webkit-box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);  height: 10em;  width: 10em;  margin: 1em 1em 2em 1em;}.container .canvas .spinner4 {  width: 3em;  height: 3em;  border: 7px transparent solid;  border-left: 7px #4DB6AC solid;  border-radius: 50%;  -webkit-animation: spinner4 1s linear infinite;  animation: spinner4 1s linear infinite;}@-webkit-keyframes spinner4 {  100% {

            -webkit-transform: rotate(360deg);-ms-transform: rotate(360deg);-o-transform: rotate(360deg);transform: rotate(360deg);  }}

        @keyframes spinner4 {  100% {

            -webkit-transform: rotate(360deg);-ms-transform: rotate(360deg);-o-transform: rotate(360deg);transform: rotate(360deg);  }}

        .container .canvas .spinner5 {  border: 1.5em transparent solid;  border-right: 1.5em #4DB6AC solid;  border-left: 1.5em #4DB6AC solid;  border-radius: 50%;  -webkit-animation: spinner5 1s linear infinite;  animation: spinner5 1s linear infinite;}@-webkit-keyframes spinner5 {  0% {

            transform: rotate(0deg);  }  50% {transform: rotate(60deg);  }  100% {transform: rotate(360deg);  }}

        @keyframes spinner5 {  0% {

            transform: rotate(0deg);  }  50% {transform: rotate(60deg);  }  100% {transform: rotate(360deg);  }}

        .container .canvas .spinner6 {  width: 1em;  height: 1em;  border-radius: 50%;  background-color: #4db6ac;  margin: 0.1em;  -webkit-animation: fall 1s linear infinite;  animation: fall 1s linear infinite;}

        </style></head><body><div class="container"><div class="canvas"><div class="spinner4"></div></div><div class="canvas"><div class="spinner5"></div></div></div></body></html>

View Code

5.声明

案例代码是我从网上看到的,我自己模仿了一下但无论效果和方法上都不如前者。

欣慰的是能够知道原理,只是细节之处还需练习。

以上就是圆弧和扇形的加载动画该怎么写?的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

使用css3中的什么规则来定义动画

animation-play-state属性怎么用

css3中实现动画有哪两种方式

canvas的实例--时钟动画

如何判断网页中图片加载成功或者失败?

圆弧和扇形的加载动画该怎么写?

animation-delay属性怎么用

animation-duration属性有什么用

html5如何绘制动画?(代码实例)

js实现加载时锁定html页面元素的方法

更多相关阅读请进入《龙卷风》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...