• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

微信小程序懒加载数据(动画效果显示)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

来源:https://blog.csdn.net/qq_43764578/article/details/107483349

 

 

 

.wxml

<view class="index">
  <view wx:for="{{detail}}" wx:key="index" class="center {{item.hide?\'animation\':\'\'}}" id="curr{{index}}">
    <view wx:if="{{item.hide}}">
      {{item.name}}{{index}}
    </view>
  </view>
</view>

 

.wxss

.index{
  width: 100%;
  float: left;
  min-height: 100vh;
  background-color: #ffcccc;
  padding-bottom: 30rpx;
}
.center{
  width: 80%;
  margin: 30rpx 10% 0;
  float: left;
  font-size: 26rpx;
  height: 200rpx;
  background-color: #fff;
}
.animation{
  animation:center 1s;
}
@keyframes center{
  from {
    transform:scale(0.3);
  }
  to {
    transform:scale(1);
  }
}

 

.js

Page({
  data: {
    detail: [{ name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }, { name: \'测试\' }],
    windowHeight: \'\',
  },
  onLoad: function (opstion) {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          windowHeight: res.windowHeight
        })
      },
    })
    for (let i = 0; i < that.data.detail.length; i++) {
      wx.createSelectorQuery().select(\'#curr\' + i).boundingClientRect(function (rect) {
        that.data.detail[i].height = rect.top
        if (that.data.detail[i].height <= that.data.windowHeight) {
          that.data.detail[i].hide = true
        } else {
          that.data.detail[i].hide = false
        }
        if (i == (that.data.detail.length - 1)) {
          that.setData({
            detail: that.data.detail
          })
        }
      }).exec()
    }
  },
  onPageScroll: function (e) {
    let that = this
    if (that.data.detail[that.data.detail.length - 1].hide) {
      return false
    }
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          windowHeight: res.windowHeight + e.scrollTop
        })
      },
    })
    for (let i = 0; i < that.data.detail.length; i++) {
      if (that.data.detail[i].height <= that.data.windowHeight) {
        that.data.detail[i].hide = true
      } else {
        that.data.detail[i].hide = that.data.detail[i].hide ? true : false
      }
    }
    that.setData({
      detail: that.data.detail
    })
  },
})

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
微信小程序 - 上拉加载发布时间:2022-07-18
下一篇:
微信小程序image懒加载问题汇总发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap