mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 00:31:20 -08:00
isInViewport添加offset
This commit is contained in:
1 parent
d73666475c
commit
2ea92640aa
4 files changed
+9
-8
No files matched your search
@@ -65,12 +65,12 @@ export function tooltip(target, msg, pos = 'up') {
|
||||
target.setAttribute('data-balloon-pos', pos);
|
||||
}
|
||||
|
||||
export function isInViewport(el) {
|
||||
export function isInViewport(el, offset = 0) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
const windowHeight = window.innerHeight || document.documentElement.clientHeight;
|
||||
const windowWidth = window.innerWidth || document.documentElement.clientWidth;
|
||||
const vertInView = rect.top <= windowHeight && rect.top + rect.height >= 0;
|
||||
const horInView = rect.left <= windowWidth && rect.left + rect.width >= 0;
|
||||
const vertInView = rect.top <= windowHeight + offset && rect.top + rect.height + offset >= 0;
|
||||
const horInView = rect.left <= windowWidth + offset && rect.left + rect.width + offset >= 0;
|
||||
return vertInView && horInView;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user