进入下面小程序可以体验效果:
WXML:
<wxs module="img" src="./loading.wxs"></wxs>
<view class="loading-container {{show?'':'loading-container-hide'}}">
<view class="loading-mask" wx:if="{{mask&&show}}"></view>
<view class="loading-mask-solid {{!mask&&show?'':'loading-mask-solid-hide'}}"></view>
<view class="loading">
<view class="loading-inner {{open?'loading-inner-open':''}}"></view>
<view class="loading-circle"></view>
<view class="loading-petal {{open?'loading-petal-open':''}}">
<view class="loading-petal-1">
<image src="{{img.imgBase64}}"></image>
</view>
<view class="loading-petal-2">
<image src="{{img.imgBase64}}"></image>
</view>
<view class="loading-petal-3">
<image src="{{img.imgBase64}}"></image>
</view>
<view class="loading-petal-4">
<image src="{{img.imgBase64}}"></image>
</view>
<view class="loading-petal-5">
<image src="{{img.imgBase64}}"></image>
</view>
</view>
</view>
</view>
WXSS:
.loading-container{
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
opacity: 1;
}
.loading-container-hide{
opacity: 0;
transform: scale(0);
transition: all 0.7s;
}
.loading-mask{
height: 100%;
width: 100%;
position: absolute;
backdrop-filter: blur(5px);
background: #ffffffad;
}
.loading-mask-solid{
height: 100%;
width: 100%;
position: absolute;
background: white;
}
.loading-mask-solid-hide{
opacity: 0;
transition: all 0.5s;
}
.loading{
position: absolute;
width: 200rpx;
height: 200rpx;
animation: loadingMove 1.5s alternate infinite;
animation-timing-function: ease;
display: flex;
justify-content: center;
align-items: center;
}
.loading-petal{
position: absolute;
opacity: 0;
width: 160rpx;
height: 160rpx;
transform: scale(0.5);
}
.loading-petal-open{
opacity: 1;
transform: scale(1.2);
transition: all 0.5s;
}
.loading-petal-1{
position: absolute;
animation: loadingpetal linear infinite 1.5s;
}
.loading-petal-2{
position: absolute;
animation: loadingpetal linear infinite 4s;
}
.loading-petal-3{
position: absolute;
animation: loadingpetal linear infinite reverse 2s;
}
.loading-petal-4{
position: absolute;
animation: loadingpetal linear infinite reverse 3.5s;
}
.loading-petal-5{
position: absolute;
animation: loadingpetal linear infinite reverse 4.5s;
}
@keyframes loadingpetal {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
image{
width: 160rpx;
height: 160rpx;
}
.loading-inner{
width: 65rpx;
height: 65rpx;
background: rgb(71 135 255);
border-radius: 100px;
display: flex;
justify-content: center;
align-items: center;
}
.loading-inner-open{
background: rgb(0 66 189);
width: 110rpx;
height: 110rpx;
transition: all 0.5s;
}
@keyframes loadingMove {
0%,100%{
transform: translateY(0);
}
50%{
transform: translateY(-8px);
}
}
.loading-circle {
position: absolute;
z-index: 99;
font-size: 16px;
width: 16px;
height: 16px;
display: block;
background: transparent url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23ffffff' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23ffffff' stop-opacity='0' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23ffffff' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23ffffff' stop-opacity='0' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23ffffff' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A") no-repeat;
background-size: 100%;
animation: loading linear infinite 1s;
animation-timing-function: ease;
}
@keyframes loading {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
JS:
// components/loading/loading.js
Component({
lifetimes:{
created(){
},
attached(){
}
},
observers: {
'show': function(show) {
var that =this;
if(show){
setTimeout(()=>{
that.setData({open:true,mask:true})
},that.data.burstTime)
}else{
that.setData({mask:false})
setTimeout(()=>{
that.setData({open:false})
},500)
}
}
},
/**
* 组件的属性列表
*/
properties: {
/**
* 是否显示
*/
show:{
type:Boolean,
value:false
},
/**
* 花瓣绽放时间
*/
burstTime:{
type:Number,
value:1300
}
},
/**
* 组件的初始数据
*/
data: {
mask:false,
open:false,
},
/**
* 组件的方法列表
*/
methods: {
}
})
WXS:
var imagebase64="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAAC0CAYAAAA9zQYyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAJVWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgOS4wLWMwMDEgNzkuYzAyMDRiMiwgMjAyMy8wMi8wOS0wNjoyNjoxNCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9Ii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NcGGnZ98nFBaDXQqekbmsJsolvVhnowvzQF5m9Ezol9jNzeGLGFt5ZoaclxqFvT9xLoVXqLZX6Gf5lipQYJ0XuaY5SaJV6U1O6i4eZIC3Svt7MnCB0MVLLAnGbxWImiz8vOhlBC01dHW+9HLTQKnXLHB6b8QJPF2J6l0kwH0wflNAzJcjThNbeXUxbcj3fS4zghU6JTRfk7lTu+9rFiFZolbpuDlKGyIWYeuQiDzWVT2x8PyBC55/WInaHVA6bKIRO1dZTsWPphIjA/RBr5eiFTond1MViyGWIlBdyr99ZSB0MhF5M7GZAiS2JPIhR5OiFToktUjc8L0UkjeVy9dDny9YIna3YVRV7U0sR1+XuaWkhiXweS42M0KvJLULXzNi4Q+61Ap7WtUosLbcf36Oe1xfxIHRYcj9QqafH+3PSey1DeYW/kptPkhKJL0lihLYleE3Flp+rqeP0sWUEF1HHOuTnr6nHJIUvOesInbfkcmtYRYW+rw/Ln+VjImZv6pWbTr8nNx8OLvytAk98utUJoQFyoMQpAIQGQGgAhAZAaEBoAIQGQGgAhAZAaIiQfwCoeDQSJB4DDAAAAABJRU5ErkJggg=="
module.exports = {
imgBase64: imagebase64
}
readme.me使用方式:
使用方式:
直接引入组件
<loading style="position: absolute;height: 100%;width: 100%;transition: all 0.2s;z-index: {{loadingShow?9999:0}};"
show="{{true}}"
burstTime="{{1000}}">
</loading>
说明:
必须使用该style: position: absolute;height: 100%;width: 100%;transition: all 0.2s;z-index: {{loadingShow?9999:0}};
show: 是否显示
burstTime: 花瓣绽放时间 单位/ms. 参数0,直接显示花瓣加载动画