javascript-tutorial / javascript-tutorial/en.javascript.info
Intersection Observer API
還沒有人認領這個 Issue。
- 主要語言
- HTML
- 星號
- 25.5k
- 分支
- 4k
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hey!
Would be nice to see a topic about the Intersection Observer API: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
I used it one time, where I made a navbar sticky, whenever the user scrolling down and the hero section is no longer in the viewport. Example:
function stickyHeaderHandling() {
const sectionHero = document.getElementById("hero-section");
const navHeader = document.getElementById("nav-header");
const stickyNav = function (entries) {
const [entry] = entries;
if (!entry.isIntersecting) {
navHeader.classList.add("sticky--header");
} else {
navHeader.classList.remove("sticky--header");
}
};
const heroObserver = new IntersectionObserver(stickyNav, {
root: null,
threshold: 0.1,
});
heroObserver.observe(sectionHero);
}
Also you can use it for lazy loading images, or animate html elements whenever the elements get into the viewport(https://www.itzami.com/blog/boost-your-css-animations-with-intersection-observer-api).
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
以連結的 MDN Intersection Observer API 頁面作為起始參考。查看提供的 sticky navbar 範例,並考慮建議的 lazy-loading 和由 viewport 觸發的動畫使用情境。完成標準是形成一個範圍明確且包含 Intersection Observer API 範例的完整教學主題。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript
- 領域
- documentation, web-dev
- Issue 類型
- 文件
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100