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

修正lazyload有时候失效的问题 #1090

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ Fluid.utils = {
elementVisible: function(element, offsetFactor) {
offsetFactor = offsetFactor && offsetFactor >= 0 ? offsetFactor : 0;
var rect = element.getBoundingClientRect();
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
return (
(rect.top >= 0 && rect.top <= viewportHeight * (1 + offsetFactor) + rect.height / 2) ||
(rect.bottom >= 0 && rect.bottom <= viewportHeight * (1 + offsetFactor) + rect.height / 2)
);
const viewportHeight = (window.innerHeight || document.documentElement.clientHeight) * (1 + offsetFactor);
const viewportWidth = (window.innerWidth || document.documentElement.clientWidth) * (1 + offsetFactor);

// 判断元素的顶部、底部、左侧或右侧是否在视口内
// 如果有一个在视口内,则认为元素可见
return rect.top < viewportHeight || rect.bottom > 0 || rect.left < viewportWidth || rect.right > 0;
},

waitElementVisible: function(selectorOrElement, callback, offsetFactor) {
Expand Down
Loading