给大家提供一个小程序动态加载效果,loading加载效果 的代码示例 ,效果如下,仅供参考
效果0
效果1
效果2,3自己拷代码看吧
在wxml中的<swiper>标签中 把不看的效果注释 把想看的效果去掉注释就OK了
wxml
<!--动态加载效果 -->
<button bindtap='a'>显示</button>
<button bindtap='b'>隐藏</button>
<view class="b1" hidden="{{flag}}">
<view class="t_w">
<!-- <view class="b2"> -->
<swiper>
<!--效果0 -->
<swiper-item>
<view class="spinner">
<view class="spinner-container container1">
<view class="circle1"></view>
<view class="circle2"></view>
<view class="circle3"></view>
<view class="circle4"></view>
</view>
<view class="spinner-container container2">
<view class="circle1"></view>
<view class="circle2"></view>
<view class="circle3"></view>
<view class="circle4"></view>
</view>
<view class="spinner-container container3">
<view class="circle1"></view>
<view class="circle2"></view>
<view class="circle3"></view>
<view class="circle4"></view>
</view>
</view>
</swiper-item>
<!-- 效果1 -->
<!-- <swiper-item>
<view>
<image class='imgmodo' src='../../img/logo.png'></image>
</view>
<view class="spinner1">
<view class="bounce1"></view>
<view class="bounce2"></view>
<view class="c"></view>
</view>
</swiper-item> -->
<!--效果2 -->
<!-- <swiper-item>
<view class="spinner2">
<view class="dot1"></view>
<view class="dot2"></view>
</view>
</swiper-item> -->
<!--效果3 -->
<!-- <swiper-item>
<view class="spinner3">
<view class="rect1"></view>
<view class="rect2"></view>
<view class="rect3"></view>
<view class="rect4"></view>
<view class="rect5"></view>
</view>
</swiper-item> -->
</swiper>
</view>
</view>
<!--动态加载结束 -->
wxss代码
.b1 {
position: fixed;
width: 100%;
height: 100%;
/* background: rgba(0, 0, 0, 0); */
background: rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.t_w {
width: 300rpx;
height: 300rpx;
margin-left: 220rpx;
margin-top: 60rpx;
background: rgba(0, 0, 0, 0.4);
border-radius: 20rpx;
}
.b21 {
width: 300rpx;
height: 300rpx;
margin: 35% auto;
/* margin: 300rpx auto; */
background-color: #fff;
border-radius: 150rpx;
}
.imgmodo {
margin-left: 50rpx;
margin-top: 30rpx;
width: 200rpx;
height: 200rpx;
border-radius: 40rpx;
opacity: 0.9;
/* filter:alpha(opacity=40); */
}
/*-------------------效果0--------------- */
.spinner {
margin: 100px auto;
width: 30px;
height: 30px;
position: relative;
}
.container1 view, .container2 view, .container3 view{
width: 8px;
height: 8px;
/* background-color: #fff; 加载效果的颜色 */
background-color: green;
border-radius: 100%;
position: absolute;
-webkit-animation: bouncedelay 1.2s infinite ease-in-out;
animation: bouncedelay 1.2s infinite ease-in-out;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.spinner .spinner-container {
position: absolute;
width: 100%;
height: 100%;
}
.container2 {
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
.container3 {
-webkit-transform: rotateZ(90deg);
transform: rotateZ(90deg);
}
.circle1 { top: 0; left: 0; }
.circle2 { top: 0; right: 0; }
.circle3 { right: 0; bottom: 0; }
.circle4 { left: 0; bottom: 0; }
.container2 .circle1 {
-webkit-animation-delay: -1.1s;
animation-delay: -1.1s;
}
.container3 .circle1 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
.container1 .circle2 {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.container2 .circle2 {
-webkit-animation-delay: -0.8s;
animation-delay: -0.8s;
}
.container3 .circle2 {
-webkit-animation-delay: -0.7s;
animation-delay: -0.7s;
}
.container1 .circle3 {
-webkit-animation-delay: -0.6s;
animation-delay: -0.6s;
}
.container2 .circle3 {
-webkit-animation-delay: -0.5s;
animation-delay: -0.5s;
}
.container3 .circle3 {
-webkit-animation-delay: -0.4s;
animation-delay: -0.4s;
}
.container1 .circle4 {
-webkit-animation-delay: -0.3s;
animation-delay: -0.3s;
}
.container2 .circle4 {
-webkit-animation-delay: -0.2s;
animation-delay: -0.2s;
}
.container3 .circle4 {
-webkit-animation-delay: -0.1s;
animation-delay: -0.1s;
}
@-webkit-keyframes bouncedelay {
0%, 80%, 100% { -webkit-transform: scale(0.0) }
40% { -webkit-transform: scale(1.0) }
}
@keyframes bouncedelay {
0%, 80%, 100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
} 40% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
.spinner1 {
/* margin: 100px auto 0;
width: 150px;
text-align: center; */
margin-top: -15rpx;
margin-left: 120rpx;
}
.spinner1 view {
width: 8px;
height: 8px;
/* background-color: #fff; */
background-color: green;
border-radius: 100%;
display: inline-block;
-webkit-animation: bouncedelay 1.4s infinite ease-in-out;
animation: bouncedelay 1.4s infinite ease-in-out;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.spinner1 .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner1 .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
@-webkit-keyframes bouncedelay {
0%, 60%, 100% {
-webkit-transform: scale(0.0);
}
40% {
-webkit-transform: scale(1.0);
}
}
@keyframes bouncedelay {
0%, 60%, 100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
}
40% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}
/*--------------------------------------------------*/
/*效果二 */
/*--------------------------------------------------*/
.spinner2 {
margin: 100px auto;
width: 20px;
height: 20px;
position: relative;
text-align: center;
-webkit-animation: rotate 2.0s infinite linear;
animation: rotate 2.0s infinite linear;
}
.dot1, .dot2 {
width: 60%;
height: 60%;
display: inline-block;
position: absolute;
top: 0;
background-color: #fff;
border-radius: 100%;
-webkit-animation: bounce 2.0s infinite ease-in-out;
animation: bounce 2.0s infinite ease-in-out;
}
.dot2 {
top: auto;
bottom: 0px;
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
@-webkit-keyframes rotate { 100% { -webkit-transform: rotate(360deg) }}
@keyframes rotate { 100% { transform: rotate(360deg); -webkit-transform: rotate(360deg) }}
@-webkit-keyframes bounce {
0%, 100% { -webkit-transform: scale(0.0) }
50% { -webkit-transform: scale(1.0) }
}
@keyframes bounce {
0%, 100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
} 50% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}
/*------------------------------------*/
/*-------------效果3-----------------------*/
.spinner3 {
margin: 100px auto;
width: 50px;
height: 60px;
text-align: center;
font-size: 10px;
}
.spinner3 view {
background-color: #fff;
height: 100%;
width: 6px;
display: inline-block;
margin-left: 2px;
-webkit-animation: stretchdelay 1.2s infinite ease-in-out;
animation: stretchdelay 1.2s infinite ease-in-out;
}
.spinner3 .rect2 {
-webkit-animation-delay: -1.1s;
animation-delay: -1.1s;
}
.spinner3 .rect3 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
.spinner3 .rect4 {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.spinner3 .rect5 {
-webkit-animation-delay: -0.8s;
animation-delay: -0.8s;
}
@-webkit-keyframes stretchdelay {
0%, 40%, 100% { -webkit-transform: scaleY(0.4) }
20% { -webkit-transform: scaleY(1.0) }
}
@keyframes stretchdelay {
0%, 40%, 100% {
transform: scaleY(0.4);
-webkit-transform: scaleY(0.4);
} 20% {
transform: scaleY(1.0);
-webkit-transform: scaleY(1.0);
}
}
js
Page({
/**
* 页面的初始数据
*/
data: {
flag: false,
},
a: function () {
this.setData({ flag: false })
},
b: function () {
this.setData({ flag: true })
}
,
})