Track Element Visibility Like a Pro: Intersection Observer v2
CODE PREVIEW
Prompt
Create a demo page that visualizes the visibility state of multiple <div> cards using Intersection Observer v2. Each card should display its current visibility (fully visible, partially visible, not visible) in real-time, with a colored border indicator. Use a scrollable container with randomized card positions.
Intersection Observer v2 は、元のAPIを強化し、intersectionRatio や複数のしきい値(threshold)を設定できるようになりました。このデモでは、ランダムな縦オフセットを持つカードをスクロール可能なグリッドに配置し、可視状態をリアルタイムで色分け表示します。非表示(赤)→ 部分可視(オレンジ)→ 完全可視(緑)と変化するボーダーが、v2の強力な可視性検出を示します。
Prompt Overview
Intersection Observer v2 enhances the original API by providing more precise visibility data, such as intersectionRatio and the ability to use multiple thresholds. This demo creates a scrollable grid of cards, each with a random vertical offset, and tracks their visibility in real-time. The border color changes from red (not visible) to orange (partially visible) to green (fully visible), demonstrating how to use multiple thresholds to create a rich visibility experience.
Was this prompt helpful?
Comments
Comments appear after moderation
この記事が役に立ったら投げ銭で応援
Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済
開発者が選ぶ最強ツール集
運営者が毎日使っているツール・ガジェット 6選