Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION]如何判断已经滚动到了底部 #256

Open
xmsz-stu opened this issue Feb 22, 2024 · 2 comments
Open

[QUESTION]如何判断已经滚动到了底部 #256

xmsz-stu opened this issue Feb 22, 2024 · 2 comments

Comments

@xmsz-stu
Copy link

我通过ref.current.getScrollInfo拿到的信息很奇怪
我的高度设置的是200,内容高度是动态(获取到的是700),然后滚动到底部的时候scrollInfo.y显示的500,这个500的值应该是内容高度700-高度200.
但是我拿不到这个700的值,我就无法判断是否滚动到底部了

所以getScrollInfo能不能暴露更多的信息?

@NameWjp
Copy link
Contributor

NameWjp commented Mar 26, 2024

可以获取 .rc-virtual-list-holder 的

temp2.getBoundingClientRect().y + temp2.getBoundingClientRect().height

和 .rc-virtual-list-holder-inner 的

temp3.getBoundingClientRect().y + temp3.getBoundingClientRect().height

是否相等,不过感觉还是 getScrollInfo 暴露更多信息更好,这些写就耦合了 dom 结构

@NameWjp
Copy link
Contributor

NameWjp commented Mar 26, 2024

研究了下上面的方法不太准,可以使用下面的方法

const RC_VIRTUAL_LIST_HOLDER_CLASS = '.rc-virtual-list-holder'

export const isScrollBottom = (root: HTMLElement) => {
  const virtualList = root.querySelector(RC_VIRTUAL_LIST_HOLDER_CLASS)
  if (!isDef(virtualList)) {
    throw virtualError(`cannot find class ${RC_VIRTUAL_LIST_HOLDER_CLASS}`)
  }
  return virtualList.scrollTop >= virtualList.scrollHeight - virtualList.clientHeight
}

export const isScrollTop = (root: HTMLElement) => {
  const virtualList = root.querySelector(RC_VIRTUAL_LIST_HOLDER_CLASS)
  if (!isDef(virtualList)) {
    throw virtualError(`cannot find class ${RC_VIRTUAL_LIST_HOLDER_CLASS}`)
  }
  return virtualList.scrollTop <= 0
}

export const hasScroll = (root: HTMLElement) => {
  const virtualList = root.querySelector(RC_VIRTUAL_LIST_HOLDER_CLASS)
  if (!isDef(virtualList)) {
    throw virtualError(`cannot find class ${RC_VIRTUAL_LIST_HOLDER_CLASS}`)
  }
  return virtualList.scrollHeight > virtualList.clientHeight
}

yoyo837 pushed a commit that referenced this issue Apr 5, 2024
* fix: adjust inVirtual logic(#227)

* feat: support detection size(#256)

* fix: check whether scrollWidth exist(#261)

* fix: fix maxScrollHeight negative

* test: add scrollbar thumb test

* fix: add annotation

---------

Co-authored-by: wangjinping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants