gpt4 book ai didi

javascript - 检测覆盖 iframe 的系统窗口

转载 作者:IT王子 更新时间:2023-10-29 03:22:24 25 4
gpt4 key购买 nike

看了this youtube video之后我很好奇显示的某些功能如何用 JS 实现。

我的主要问题之一是如何检测 iframe 上的另一个系统窗口(如视频中显示的单词窗口)。

关于 another video有迹象表明该技术基于浏览器优化 View 外元素的渲染这一事实。

我无法了解使用的确切方法/属性是什么。

你有什么想法?

最佳答案

据我所知,可以检测页面是在前台还是在后台 - 或者更准确地说:是否有焦点。

var focus = true;
window.onblur = function() { focus = false; action(); }
window.onfocus = function() { focus = true; action(); }

document.onblur = window.onblur;
document.focus = window.focus;

function action(){
if(focus) {
document.body.style.background = "green";
} else {
document.body.style.background = "lightgray";
}
}
try click inside and then outside

上面的代码片段使用了事件监听器 onbluronfocus事件 focusblur .


更好的是使用Visibility API :

  • 它在切换标签时有效(页面可以检测到用户打开了另一个标签)

Note: While onblur and onfocus will tell you if the user switches windows, it doesn't necessarily mean it's hidden. Pages only become hidden when the user switches tabs or minimizes the browser window containing the tab.

参见 Detect if browser tab is active or user has switched away

http://jsbin.com/lowocepazo/edit?js,output


对于滚动有一个 Intersection Observer

provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document's viewport


//编辑:现在无法检测到此类情况,例如在您发布的第一个视频(2:09)中,当另一个窗口被某些元素遮挡时:enter image description here

如果我错了,请指正。

相关:

关于javascript - 检测覆盖 iframe 的系统窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50605078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com