内容简介:一个用于过渡的加载组件,效果图:如上图分为三个部分:上板、下板、中部; 中部又分为上半沙漏和下半沙漏, 我以上半沙漏为例:主要有4个动画:
一个用于过渡的加载组件,效果图:
技术栈
vue css,html
实现思路
1.沙漏主体设计
<template>
<div class="hour-container" >
<div class="upper-tap"></div>
<div class="middle-tap">
<div class="upper-half-container">
<div class="upper-half-content">
<div class="upper-sand" >
<div class="sand-reduce"></div>
</div>
</div>
</div>
<div class="lower-half-container">
<div class="lower-half-content">
<div class="lower-sand">
<div class="sand-add"></div>
</div>
</div>
</div>
</div>
<div class="sand-falling">
<div class="sand-null"></div>
</div>
<div class="bottom-tap"></div>
</div>
</template>
复制代码
如上图分为三个部分:上板、下板、中部; 中部又分为上半沙漏和下半沙漏, 我以上半沙漏为例:
<div class="upper-half-container">
<div class="upper-half-content">
<div class="upper-sand" >
<div class="sand-reduce"></div>
</div>
</div>
</div>
复制代码
.upper-half-container{ /*上下沙漏各占一半,overflow: hidden*/
width: 100%;
height: 50%;
overflow: hidden;
position: relative;
}
.upper-half-content{ /*通过border-radius,width,height形成椭圆,加上border*/
position: absolute;
border: 3px solid rgb(248, 248, 250);
border-radius: 50%;
height: 105px;
width: 50px;
top: -53px;
left: 2px;
box-shadow: 2px 1px 3px 0px #aaa;
}
.upper-sand{ /*里面的沙子,overflow: hidden*/
width: 100%;
height: 100%;
background-color: #409EFF;
position: absolute;
border-radius: 50%;
top: 0px;
overflow: hidden;
}
.sand-reduce{ /*通过动画控制height,来体现沙子减少*/
height: 60%;
width: 100%;
background-color: #fff;
animation: sand-reduce 4s linear infinite;
}
@keyframes sand-reduce{ /*动画*/
0%{
height: 65%;
}
25%{
height: 78%;
}
40%{
height: 89%;
}
62.5%{
height: 100%;
}
80%{
height: 100%;
}
100%{
height: 100%;
}
}
复制代码
2.动画效果
主要有4个动画: 上沙漏减少 、 下沙漏增加 、 下落的沙子 、 沙漏的旋转
原理和上面的 上沙漏 基本相同
<div class='parent'>
<div class='child'></div>
</div>
复制代码
沙子的增加或减少: 通过动画控制子元素的高度体现增加和减少
比较关键的是: 控制4个动画的衔接
我定了一个动画的周期为 4s :
-
上沙漏减少在0s~2.5s减少,2.5~4s不变 -
下沙漏增加在0s~0.5s不变,0.5~3s增加,3s~4s不变 -
下落的沙子在0s~0.5s增加,0.5~2.5s不变,2.5s~3s减少,3s~4s不变 -
沙漏的旋转在0s~3s不变,3~4s旋转
说明
该组件基于 vue , 收录在我的 jk -ui 库的 Loading模块 下, 演示文档
你也可以通过 npm run --save jk-ui
<j-hour></j-hour> 使用
具体源码
觉得有用的话,欢迎 Star , 感谢:pray:
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- React 组件模式-有状态组件 x 无状态组件、容器组件 x 展示组件、高阶组件 x 渲染回调(函数作为子组件)
- Serverless 组件开发尝试:全局变量组件和单独部署组件
- angular自定义组件-UI组件篇-switch组件
- React Hooks 源码解析(一):类组件、函数组件、纯组件
- Vue动态组件和异步组件
- Vue 动态组件 & 异步组件原理
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Collective Intelligence实战
阿拉克 / 2010-9 / 58.00元
《Collective Intelligence实战》内容简介:在互联网上,利用用户的集体智慧是成功的关键。集体智慧是一种新兴的编程技术,可让您从人们访问web和与web交互的过程中找到有价值的模式、发现这些访问者之间的关系和确定他们的个人偏好及习惯等。《collective Intelligence实战》首先介绍了集体智慧的原则和构建更具交互性网站的思想,然后通过示例开发了一个直接可用的基于Ja......一起来看看 《Collective Intelligence实战》 这本书的介绍吧!