小程序加载屏幕骨架组件支持
发布于 4 年前 作者 qiangdong 1769 次浏览 来自 分享

component/skeleton/index.js

Component({
  properties: {
    show: {
      typeBoolean,
      valuetrue
    },
    loading: {
      typeBoolean,
      valuefalse
    },
  },
  attachedfunction () {
    const systemInfo = wx.getSystemInfoSync();
    this.setData({
      systemInfo: {
        width: systemInfo.windowWidth,
        height: systemInfo.windowHeight
      },
    })
  },
  readyfunction () {
    if(this.properties.loading == false){
      setTimeout(() => {
        this.setData({
          showfalse
        })
      },1500)
    }
  },
  methods: {
    //锁屏
    touchmovefunction () {
    }
  },
})

component/skeleton/index.json

{
  "component"true
}

component/skeleton/index.wxml

<view class="skeleton" catchtouchmove="touchmove" style="width: {{systemInfo.width}}px; height: {{systemInfo.height}}px;" wx:if="{{show}}">
  <view class="header">
    <view class='skeleton-text'>
      <view class='line lineA'></view>
      <view class='line lineB'></view>
      <view class='line lineC'></view>
    </view>
  </view>
  <view class="bottom">
    <view class="skeleton-h1 animation"></view>
    <view class="skeleton-h2 animation"></view>
    <view class="skeleton-h3 animation"></view>
    <view class="skeleton-h4 animation"></view>
    <view class="skeleton-head animation"></view>
    <view class="skeleton-body">
      <view class="skeleton-100 animation"></view>
      <view class="skeleton-80 animation skeleton-mt"></view>
    </view>
    <view class="skeleton-head animation"></view>
    <view class="skeleton-body">
      <view class="skeleton-80 animation"></view>
      <view class="skeleton-100 animation skeleton-mt"></view>
    </view>
    <view class="skeleton-head animation"></view>
    <view class="skeleton-body">
      <view class="skeleton-100 animation"></view>
      <view class="skeleton-80 animation skeleton-mt"></view>
    </view>
  </view>
</view>

component/skeleton/index.wxss

/*加载骨架*/
.skeleton{position:fixed;z-index9999;height100%;width100%;bottom:0px;top:0px;background:#fff;box-sizing: border-box;background-color:#F8F6F8;}
.animation{-webkit-animation:skeleton-animate 1.2s ease-in-out infinite;animation:skeleton-animate 1.2s ease-in-out infinite;}
.skeleton .skeleton-head,.skeleton .skeleton-100,.skeleton .skeleton-80,.skeleton .skeleton-60{background:#F8F6F8;float:left;border-radius:10px}
.skeleton-h1 {width:40%;height:20px;margin-bottom:10px;border-radius:10px;background:#FFE8E8}
.skeleton-h2{width:35%;height:10px;margin-bottom:20px;border-radius:10px;background:#F8F6F8}
.skeleton-h3{width:100%;height:30px;margin-bottom:10px;border-radius:10px;background:#F8F6F8}
.skeleton-h4{width:80%;height:20px;margin-bottom:20px;border-radius:10px;background:#F8F6F8}
.skeleton-head {width:20%;height:80px;margin-bottom:10px;}
.skeleton-body {margin-left:22%;height80px;margin-bottom:10px;}
.skeleton-100 {width:100%;height40px;}
.skeleton-80 {width:80%;height30px;}
.skeleton-60 {width:60%;height30px;}
.skeleton-mt{margin-top:10px;}
.skeleton-text{color#FF0000;text-align: center;line-height:30px;font-size:28rpx;}
.line{display: inline-block;width:5px;height:5px;border-radius15px;margin:0px 5px;background:#ccc}
[@keyframes](/user/keyframes) loading{50%{width30px}100%{width:5px}}
.lineA{animation: loading 1.5s 0s infinite}
.lineB{animation: loading 1.5s 0.3s infinite}
.lineC{animation: loading 1.5s 0.6s infinite}
.header{position: absolute;left:10px;right:10px;top:10%;}
.bottom{position: absolute;bottom:0px;left:0px;right:0px;background-color:#FFF;padding10px;}
[@keyframes](/user/keyframes) skeleton-animate{50%{opacity:.4}}

在页面中调用框架

//json中引入组件
"usingComponents": {
    "skeleton""./component/skeleton/index",
}
//wxml页面中插入
<skeleton />
回到顶部