| 53 | |
| 54 | methods: { |
| 55 | onScroll({ scrollTop }: { scrollTop?: number } = {}) { |
| 56 | const { container, offsetTop, disabled } = this.data; |
| 57 | |
| 58 | if (disabled) { |
| 59 | this.setDataAfterDiff({ |
| 60 | fixed: false, |
| 61 | transform: 0, |
| 62 | }); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | this.scrollTop = scrollTop || this.scrollTop; |
| 67 | |
| 68 | if (typeof container === 'function') { |
| 69 | Promise.all([getRect(this, ROOT_ELEMENT), this.getContainerRect()]) |
| 70 | .then(([root, container]) => { |
| 71 | if (offsetTop + root.height > container.height + container.top) { |
| 72 | this.setDataAfterDiff({ |
| 73 | fixed: false, |
| 74 | transform: container.height - root.height, |
| 75 | }); |
| 76 | } else if (offsetTop >= root.top) { |
| 77 | this.setDataAfterDiff({ |
| 78 | fixed: true, |
| 79 | height: root.height, |
| 80 | transform: 0, |
| 81 | }); |
| 82 | } else { |
| 83 | this.setDataAfterDiff({ fixed: false, transform: 0 }); |
| 84 | } |
| 85 | }) |
| 86 | .catch(() => {}); |
| 87 | |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | getRect(this, ROOT_ELEMENT).then((root) => { |
| 92 | if (!isDef(root) || (!root.width && !root.height)) { |
| 93 | return; |
| 94 | } |
| 95 | if (offsetTop >= root.top) { |
| 96 | this.setDataAfterDiff({ fixed: true, height: root.height }); |
| 97 | this.transform = 0; |
| 98 | } else { |
| 99 | this.setDataAfterDiff({ fixed: false }); |
| 100 | } |
| 101 | }); |
| 102 | }, |
| 103 | |
| 104 | setDataAfterDiff(data) { |
| 105 | wx.nextTick(() => { |