graceLazyload.js 999 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. 懒加载
  3. 来自 grace.hcoder.net
  4. 作者 hcoder 深海 5213606@qq.com
  5. 版权声明 :
  6. GraceUI 的版权约束是不能转售或者将 GraceUI 直接发布到公开渠道!
  7. 侵权必究,请遵守版权约定!
  8. */
  9. var graceLazyWinHeight = 500;
  10. var graceLazyTimer = null;
  11. module.exports = {
  12. load : function(top, _page){
  13. if (graceLazyTimer != null){clearTimeout(graceLazyTimer);}
  14. graceLazyTimer = setTimeout(function(){
  15. uni.getSystemInfo({
  16. success: function (res) {
  17. graceLazyWinHeight = res.windowHeight;
  18. //遍历img
  19. uni.createSelectorQuery().selectAll('.grace-img-lazy').fields(
  20. {
  21. rect: true,
  22. }, function (res) {
  23. var isShow = [];
  24. //检查图片是否在窗口可视区域
  25. for (var i = 0; i < res.length; i++) {
  26. if (res[i].top <= graceLazyWinHeight + top) {
  27. isShow[i] = true;
  28. } else {
  29. break;
  30. }
  31. }
  32. _page.isShow = isShow;
  33. }
  34. ).exec();
  35. }
  36. });
  37. }, 200);
  38. }
  39. }