Skip to content

Instantly share code, notes, and snippets.

@zengkan0703
Last active March 6, 2020 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zengkan0703/d294f60b7133555803f8dd3b12c086e9 to your computer and use it in GitHub Desktop.
Save zengkan0703/d294f60b7133555803f8dd3b12c086e9 to your computer and use it in GitHub Desktop.
判断元素是否能滚动
function eleCanScroll(ele) {
if (!ele instanceof HTMLElement) {
console.log("fuck off");
return;
}
if (ele.scrollTop > 0) {
return true;
} else {
ele.scrollTop++;
// 元素不能滚动的话,scrollTop 设置不会生效,还会置为 0
const top = ele.scrollTop;
// 重置滚动位置
top && (ele.scrollTop = 0);
return top > 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment