屏幕是固定高度,屏幕是带滚动条的,元素在屏幕内。可能元素的底部或顶部还有内容。
假设:屏幕的 screen.top=0 px,screen.bottom=768 px
1. 元素的顶部边缘已经超过了屏幕的顶部 (也就是 element.top<0 时,)
element.topPassed = (screen.top>= element.top);
2. 元素的底部边缘已经超过屏幕顶部 (也就是 element.bottom < 0), 元素已经完全看不到了
element.bottomPassed = (screen.top>= element.bottom);
3. 元素的顶部边缘已经通过屏幕底部 (可以看到元素),[element.top < 768 px && element.bottom> 0]
element.topVisible = (screen.bottom>= element.top) && !element.bottomPassed;
4. 元素的底部边缘已经通过屏幕底部 (元素全部看得到,若元素高度超过屏幕高度,则永远为 false) [element.bottom <768 px && element.top> 0]
element.bottomVisible = (screen.bottom>= element.bottom) && !element.topPassed;
5. 元素是否有穿透,(若元素高度小于屏幕高度,当元素全部显示时,passing 则为 false ( 因为没有穿透的行为), 就是一定要有部分隐藏)[element.top<0 && element.bottom> 0]
element.passing = (element.topPassed && !element.bottomPassed);
6. 是否在屏幕上显示 ( 与 element.topVisible 一样)
element.onScreen = (element.topVisible && !element.bottomPassed);
7. 穿透的像素 ( 也就是隐藏了顶部多少高度), 不管底部
element.pixelsPassed = (screen.top - element.top);