utils.js 751 B

1234567891011121314151617181920212223242526272829303132333435
  1. export function getAllRect(context, selector) {
  2. return new Promise((resolve) => {
  3. uni.createSelectorQuery()
  4. .in(context)
  5. .selectAll(selector)
  6. .boundingClientRect()
  7. .exec((rect = []) => resolve(rect[0]));
  8. });
  9. }
  10. export function getRect(context, selector) {
  11. return new Promise((resolve) => {
  12. uni.createSelectorQuery()
  13. .in(context)
  14. .select(selector)
  15. .boundingClientRect()
  16. .exec((rect = []) => resolve(rect[0]));
  17. });
  18. }
  19. export function requestAnimationFrame(cb) {
  20. const systemInfo = uni.getSystemInfoSync();
  21. if (systemInfo.platform === 'devtools') {
  22. return setTimeout(() => {
  23. cb();
  24. }, 1000 / 30);
  25. }
  26. return uni
  27. .createSelectorQuery()
  28. .selectViewport()
  29. .boundingClientRect()
  30. .exec(() => {
  31. cb();
  32. });
  33. }