CSS3之loading效果

402f0e7cc79f91e3735e7e52f287422964a.jpg实现类似这样的等待动画效果。

第一步:如何画一个大圈,可以尝试先画两个个正方形重叠aceeb26cbaec97f3cabfcbd4292919801b5.jpg

            #circlebox{
				width: 40px;
				height: 40px;
				border: 1px solid red;
				margin: 100px;
				position: absolute;
				
			}
			#circlebox p{
				width: 12px;
				height: 12px;
				border-radius: 50%;
				background-color: #FF0000;
				position: absolute;
			}
            #circlebox p:nth-of-type(1){
				left: 0;
				top: 0;
			}
			#circlebox p:nth-of-type(2){
				right: 0;
				top: 0;
			}
			#circlebox p:nth-of-type(3){
				right: 0;
				bottom: 0;
			}
			#circlebox p:nth-of-type(4){
				left: 0;
				bottom: 0;
			}
        <div id="circlebox">
			<p></p>
			<p></p>
			<p></p>
			<p></p>
		</div>
        <div id="circlebox">
			<p></p>
			<p></p>
			<p></p>
			<p></p>
		</div>

然后让第二个正方形旋转45deg。771f4f7adc690ca2f6df1bb0f48c1e1ebd7.jpg

            #circlebox:nth-of-type(2){
				transform: rotate(45deg);
			}

再将两个正方形的边框去掉:/* border: 1px solid red; */就得到了一个大圈啦62f0ac4fb3917345012147eb452b29c18b6.jpg

第二步:让所有小圆都会变大变小 ,这里使用了CSS3 的@keyframes和scale方法

@keyframes创建动画是通过逐步改变从一个CSS样式设定到另一个。

在动画过程中,您可以更改CSS样式的设定多次。

指定的变化时发生时使用%,或关键字"from"和"to",这是和0%到100%相同。
0%是开头动画,100%是当动画完成。

使用scale()方法来将元素根据中心原点进行缩放。

            @keyframes move{
				0%{transform: scale(0);}
				50%{transform: scale(1);}
				100%{transform: scale(0);}
			}

在#circlebox p{}添加animation: move 1.5s infinite linear;让小圆在1.5s内循环变大变小

			#circlebox p{
				width: 12px;
				height: 12px;
				border-radius: 50%;
				background-color: #FF0000;
				position: absolute;
				animation: move 1.5s infinite linear;
			}

效果:37de2f4b33fb2bdbea8e77c11fefcca3a22.jpgf4674ea5c87946f1768cac419fd5ada1401.jpg73340dfb28190572085dfecc9dda3a7a760.jpg

第三步:完成上面的动画之后,要让每个小圆变大变小随时间而定,我们让第一个圆0.1s后开始变化,第二个圆0.3s后开始变化。。。。第八个圆1.5s后开始变化,这样刚好符合上面定义的 1.5s循环动画。这里需要注意的是,第二个圆实际上是第二个div里面的第一个p标签。

			#circlebox:nth-of-type(1) p:nth-of-type(1){
				animation-delay: 0.1s;
			}
			#circlebox:nth-of-type(2) p:nth-of-type(1){
				animation-delay: 0.3s;
			}
			#circlebox:nth-of-type(1) p:nth-of-type(2){
				animation-delay: 0.5s;
			}
			#circlebox:nth-of-type(2) p:nth-of-type(2){
				animation-delay: 0.7s;
			}
			#circlebox:nth-of-type(1) p:nth-of-type(3){
				animation-delay: 0.9s;
			}
			#circlebox:nth-of-type(2) p:nth-of-type(3){
				animation-delay: 1.1s;
			}
			#circlebox:nth-of-type(1) p:nth-of-type(4){
				animation-delay: 1.3s;
			}
			#circlebox:nth-of-type(2) p:nth-of-type(4){
				animation-delay: 1.5s;
			}

2fd6065bb2128418ed298eb3b8bec318145.jpg2178e948831cc2b2113404768268be818a6.jpg4f9aa1e2dd5b789debf2a08c841da3d7f70.jpg这样就完成了加载等待的动画效果啦,这是顺时针变化的,如果想让它逆时针变化的话,只需要将每个小圆的动画延时时间改为负的就行,(负的表示提前变化),这样就会从第8个圆开始变化,然后第7个、第6个。。。。。。

转载于:https://my.oschina.net/u/4069817/blog/3039999

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值