Last active
March 6, 2020 08:41
-
-
Save zengkan0703/d294f60b7133555803f8dd3b12c086e9 to your computer and use it in GitHub Desktop.
判断元素是否能滚动
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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