Skip to content

Commit 7e5d7f3

Browse files
appotryzkqiang
authored andcommitted
🐛 修正懒加载的视图判断
1 parent 096ee55 commit 7e5d7f3

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

source/js/utils.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ Fluid.utils = {
3838
elementVisible: function(element, offsetFactor) {
3939
offsetFactor = offsetFactor && offsetFactor >= 0 ? offsetFactor : 0;
4040
var rect = element.getBoundingClientRect();
41-
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
42-
return (
43-
(rect.top >= 0 && rect.top <= viewportHeight * (1 + offsetFactor) + rect.height / 2) ||
44-
(rect.bottom >= 0 && rect.bottom <= viewportHeight * (1 + offsetFactor) + rect.height / 2)
45-
);
41+
const viewportHeight = (window.innerHeight || document.documentElement.clientHeight) * (1 + offsetFactor);
42+
const viewportWidth = (window.innerWidth || document.documentElement.clientWidth) * (1 + offsetFactor);
43+
44+
// 判断元素的顶部、底部、左侧或右侧是否在视口内
45+
// 如果有一个在视口内,则认为元素可见
46+
return rect.top < viewportHeight || rect.bottom > 0 || rect.left < viewportWidth || rect.right > 0;
4647
},
4748

4849
waitElementVisible: function(selectorOrElement, callback, offsetFactor) {

0 commit comments

Comments
 (0)