HTML:
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<script src="script.js"></script>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<button>gg</button>
<h1>H1</h1>
</body>
</html>
CSS:
body{
display: grid;
}
JS:
const ConstObserver = new IntersectionObserver(entries =>
{
entries.forEach(entry =>
{
//как здесь узнать, что элемент пропал из поля зрения?
});
}, { threshold: 1 });
document.querySelectorAll("h1").forEach(el => ConstObserver.observe(el));