{"id":1804,"date":"2025-10-22T10:05:02","date_gmt":"2025-10-22T01:05:02","guid":{"rendered":"https:\/\/route-zero.com\/recruit\/?post_type=route&#038;p=1804"},"modified":"2025-12-22T10:05:15","modified_gmt":"2025-12-22T01:05:15","slug":"intersection-observer%e5%be%b9%e5%ba%95%e8%a7%a3%e8%aa%ac%ef%bd%9c%e7%94%bb%e5%83%8f%e9%81%85%e5%bb%b6%e8%aa%ad%e3%81%bf%e8%be%bc%e3%81%bf%e3%83%bbscroll%e3%82%a4%e3%83%99%e3%83%b3%e3%83%88%e6%af%94","status":"publish","type":"route","link":"https:\/\/route-zero.com\/recruit\/route\/1804\/","title":{"rendered":"Intersection Observer\u5fb9\u5e95\u89e3\u8aac\uff5c\u753b\u50cf\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\u30fbscroll\u30a4\u30d9\u30f3\u30c8\u6bd4\u8f03\u30fb\u5b9f\u88c5\u30b3\u30fc\u30c9\u4ed8\u304d"},"content":{"rendered":"<div>\n<h2>\u306f\u3058\u3081\u306b\uff5c\u3053\u306e\u8a18\u4e8b\u3067\u5f97\u3089\u308c\u308b\u4fa1\u5024<\/h2>\n<p>\n    \u300c\u30b5\u30a4\u30c8\u8868\u793a\u304c\u306a\u305c\u304b\u9045\u3044\u2026\u2026<strong>\u5148\u8f29\u304b\u3089<\/strong>\u300e\u753b\u50cf\u306e\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\u3001Intersection Observer\u3067\u5b9f\u88c5\u3057\u3068\u3044\u3066\u300f\u3068\u6307\u793a\u3055\u308c\u305f\u3051\u3069\u3001\u4f55\u304b\u3089\u624b\u3092\u3064\u3051\u308c\u3070\u3044\u3044\u3093\u3060\u2026\u2026\uff1f\u300d<br \/>\n    \u79c1\u305f\u3061<strong>\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u30a8\u30f3\u30b8\u30cb\u30a2<\/strong>\u304c\u73fe\u5834\u3067\u3088\u304f\u906d\u9047\u3059\u308b\u3001\u3053\u306e\u30e2\u30e4\u30e2\u30e4\u3002<strong>&lt;code&gt;scroll&lt;\/code&gt;\u30a4\u30d9\u30f3\u30c8<\/strong>\u306b\u306f\u6163\u308c\u3066\u3044\u3066\u3082\u3001<strong>Observer API<\/strong\n    >\u306e\u4ed5\u7d44\u307f\u3084\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u9762\u3067\u306e\u5f37\u307f\u3092\u81ea\u4fe1\u3092\u6301\u3063\u3066\u8aac\u660e\u3059\u308b\u306e\u306f\u610f\u5916\u3068\u96e3\u3057\u3044\u3082\u306e\u3067\u3059\u3002<br \/>\n    \u307e\u305a\u306f\u5b89\u5fc3\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u306e\u8a18\u4e8b\u3067\u3001<strong>JavaScript Observer API<\/strong>\u306e\u57fa\u672c\u304b\u3089\u3001\u3088\u304f\u3042\u308b\u5b9f\u88c5\u8ab2\u984c\u3067\u3042\u308b\u300c\u753b\u50cf\u306e\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\u300d\u307e\u3067\u3001\u4e00\u7dd2\u306b\u201c\u8179\u843d\u3061\u201d\u3055\u305b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n    <strong>React Hooks<\/strong>\u306b\u3088\u308b\u5b9f\u8df5\u30b3\u30fc\u30c9\u3082\u7528\u610f\u3057\u305f\u306e\u3067\u3001\u30b3\u30d4\u30da\u3067\u201c\u307e\u305a\u306f\u52d5\u304b\u3059\u201d\u3053\u3068\u304b\u3089\u59cb\u3081\u3089\u308c\u307e\u3059\u3002 <br \/>\uff08API\u306e\u57fa\u790e\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1759\/\" target=\"_blank\" rel=\"noopener\">API\u3068\u306f\uff1fSES\u73fe\u5834\u3067\u5f79\u7acb\u3064\u57fa\u790e\u301cPostman\u6d3b\u7528\u307e\u3067\u5b8c\u5168\u30ac\u30a4\u30c9<\/a\n    >\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09\n  <\/p>\n<blockquote>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1ascroll\u30a4\u30d9\u30f3\u30c8<\/strong><br \/>\n      \u30da\u30fc\u30b8\u3084\u8981\u7d20\u304c\u30b9\u30af\u30ed\u30fc\u30eb\u3055\u308c\u305f\u3068\u304d\u306b\u767a\u751f\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u3002\u983b\u7e41\u306b\u767a\u706b\u3059\u308b\u305f\u3081\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3002\n    <\/p>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aObserver API<\/strong><br \/>\n      DOM\u3084\u8981\u7d20\u306e\u72b6\u614b\u5909\u5316\u3092\u52b9\u7387\u7684\u306b\u76e3\u8996\u3067\u304d\u308bJavaScript\u306e\u4ed5\u7d44\u307f\u3002IntersectionObserver\u3001MutationObserver\u3001ResizeObserver\u306e3\u7a2e\u304c\u4ee3\u8868\u7684\u3002\n    <\/p>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aSPA\uff08Single Page Application\uff09<\/strong><br \/>\n      \u30da\u30fc\u30b8\u9077\u79fb\u3092\u305b\u305a\u306b\u30011\u3064\u306eWeb\u30da\u30fc\u30b8\u4e0a\u3067\u52d5\u7684\u306b\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u5207\u308a\u66ff\u3048\u308bWeb\u30a2\u30d7\u30ea\u306e\u69cb\u9020\u3002\u30e1\u30e2\u30ea\u7ba1\u7406\u3084\u30a4\u30d9\u30f3\u30c8\u76e3\u8996\u304c\u91cd\u8981\u3002\n    <\/p>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aReact Hooks<\/strong><br \/>\n      React\u3067\u72b6\u614b\u7ba1\u7406\u3084\u526f\u4f5c\u7528\u51e6\u7406\u3092\u95a2\u6570\u578b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u6271\u3046\u305f\u3081\u306e\u4ed5\u7d44\u307f\u3002useState\u3084useEffect\u306a\u3069\u304c\u3042\u308b\u3002\n    <\/p>\n<\/blockquote>\n<hr \/>\n<h2>1. \u306a\u305c\u4ecaObserver\u306a\u306e\u304b\uff1f- <code>scroll<\/code>\u30a4\u30d9\u30f3\u30c8\u306e\u8ab2\u984c\u3068\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9<\/h2>\n<p>\n    \u300c\u306a\u305c<code>IntersectionObserver<\/code>\u304c\u63a8\u5968\u3055\u308c\u308b\u306e\u304b\uff1f\u300d\u2014\u2014\u79c1\u305f\u3061\u304c\u76f4\u9762\u3059\u308b\u6700\u521d\u306e\u7591\u554f\u3067\u3059\u3002<br \/>\n    \u5f93\u6765\u306f\u3001<strong>&lt;code&gt;scroll&lt;\/code&gt;\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc<\/strong>\u3067\u8981\u7d20\u306e\u8868\u793a\u72b6\u614b\u3092\u76e3\u8996\u3059\u308b\u306e\u304c\u5b9a\u756a\u3067\u3057\u305f\u3002<br \/>\n    \u3057\u304b\u3057<strong>\u6700\u5927\u306e\u8ab2\u984c\u306f\u201c\u767a\u706b\u983b\u5ea6\u201d<\/strong>\u3002<br \/>\n    1\u30d4\u30af\u30bb\u30eb\u3067\u3082\u30b9\u30af\u30ed\u30fc\u30eb\u304c\u767a\u751f\u3059\u308c\u3070<strong>\u9023\u7d9a\u7684\u306b\u30a4\u30d9\u30f3\u30c8\u304c\u8d70\u308b<\/strong>\u305f\u3081\u3001\n  <\/p>\n<ul>\n<li>\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u9045\u5ef6<\/li>\n<li>\u4ed6\u306e\u64cd\u4f5c\u306e\u201c\u30ab\u30af\u3064\u304d\u201d<\/li>\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u4f4e\u4e0b<\/li>\n<\/ul>\n<p>\n    \u3053\u3046\u3057\u305f\u554f\u984c\u3092\u62db\u304d\u3084\u3059\u3044\u306e\u304c\u73fe\u5b9f\u3067\u3059\u3002<br \/>\n    \u4e00\u65b9\u3001<strong>&lt;code&gt;IntersectionObserver&lt;\/code&gt;<\/strong>\u306f\u3001\n  <\/p>\n<p>\n    \uff08Web\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u5177\u4f53\u7684\u306a\u624b\u9806\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1736\/\" target=\"_blank\" rel=\"noopener\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30bf\u30d6\u5fb9\u5e95\u89e3\u8aac\uff5cChrome DevTools\u3067Web\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u5168\u624b\u9806<\/a\n    >\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09\n  <\/p>\n<ul>\n<li><strong>\u975e\u540c\u671f\u51e6\u7406<\/strong><\/li>\n<li><strong>\u8981\u7d20\u304c\u753b\u9762\u306b\u300c\u5165\u308b\/\u51fa\u308b\u300d\u30bf\u30a4\u30df\u30f3\u30b0<\/strong>\u3060\u3051\u3067\u30b3\u30fc\u30eb\u30d0\u30c3\u30af<\/li>\n<\/ul>\n<p>\n    \u3068\u3044\u3046\u6027\u8cea\u3092\u6301\u3064\u305f\u3081\u3001\u7121\u99c4\u306a\u8a08\u7b97\u30fb\u30a4\u30d9\u30f3\u30c8\u767a\u706b\u3092\u5927\u5e45\u306b\u524a\u6e1b\u3067\u304d\u307e\u3059\u3002<br \/>\n    \u3053\u306e\u201c\u5fc5\u8981\u6700\u5c0f\u9650\u201d\u306e\u76e3\u8996\u304c<strong>\u73fe\u4ee3\u306eWeb\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584<\/strong>\u306e\u30ab\u30ae\u3067\u3059\u3002\n  <\/p>\n<hr \/>\n<h2>2. \u76ee\u7684\u5225\u306b\u9078\u3076\uff013\u3064\u306eObserver API\u4f7f\u3044\u5206\u3051\u30de\u30c3\u30d7<\/h2>\n<p><strong>JavaScript\u306b\u306f3\u7a2e\u985e\u306e\u4e3b\u8981\u306aObserver API<\/strong>\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u305e\u308c\u306e\u7279\u5fb4\u3068\u4f7f\u3044\u5206\u3051\u3092\u6574\u7406\u3057\u307e\u3059\u3002<\/p>\n<h3>1. \u8981\u7d20\u306e\u300c\u8868\u793a\u300d\u3092\u76e3\u8996\u3059\u308b\uff1a<strong>IntersectionObserver<\/strong><\/h3>\n<p>\n    <strong>\u7528\u9014\u4f8b\uff1a<\/strong>\n  <\/p>\n<ul>\n<li>\u753b\u50cf\u306e\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\uff08Lazy Loading\uff09<\/li>\n<li>\u7121\u9650\u30b9\u30af\u30ed\u30fc\u30eb<\/li>\n<li>\u8981\u7d20\u304c\u8868\u793a\u3055\u308c\u305f\u77ac\u9593\u306e\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3<\/li>\n<li>\u5e83\u544a\u306e\u30a4\u30f3\u30d7\u30ec\u30c3\u30b7\u30e7\u30f3\u8a08\u6e2c<\/li>\n<\/ul>\n<p><strong>\u300c\u8981\u7d20\u304c\u753b\u9762\u306b\u5165\u3063\u305f\u304b\uff0f\u51fa\u305f\u304b\u300d\u3092\u77e5\u308a\u305f\u3044\u5834\u5408\u306b\u6700\u9069<\/strong>\u3067\u3059\u3002<\/p>\n<blockquote>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aIntersectionObserver<\/strong><br \/>\n      \u8981\u7d20\u304c\u753b\u9762\uff08\u30d3\u30e5\u30fc\u30dd\u30fc\u30c8\uff09\u306b\u8868\u793a\u3055\u308c\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3092\u52b9\u7387\u3088\u304f\u691c\u77e5\u3067\u304d\u308bWeb API\u3002\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u3084\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\u306b\u6d3b\u7528\u3055\u308c\u308b\u3002\n    <\/p>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\uff08Lazy Loading\uff09<\/strong><br \/>\n      \u753b\u50cf\u3084\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u5fc5\u8981\u306a\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u8aad\u307f\u8fbc\u3080\u3053\u3068\u3067\u3001\u521d\u671f\u8868\u793a\u3092\u9ad8\u901f\u5316\u3057\u3001\u901a\u4fe1\u91cf\u3082\u524a\u6e1b\u3067\u304d\u308b\u624b\u6cd5\u3002\n    <\/p>\n<\/blockquote>\n<pre><code>const observer = new IntersectionObserver((entries) =&gt; {\r\n  entries.forEach(entry =&gt; {\r\n    if (entry.isIntersecting) {\r\n      console.log('\u8981\u7d20\u304c\u753b\u9762\u5185\u306b\u5165\u308a\u307e\u3057\u305f');\r\n    }\r\n  });\r\n});\r\nobserver.observe(document.querySelector('#target'));\r\n<\/code><\/pre>\n<hr \/>\n<h3>2. DOM\u8981\u7d20\u306e\u300c\u5909\u5316\u300d\u3092\u76e3\u8996\u3059\u308b\uff1a<strong>MutationObserver<\/strong><\/h3>\n<p>\n    <strong>\u7528\u9014\u4f8b\uff1a<\/strong>\n  <\/p>\n<ul>\n<li>\u8981\u7d20\u306e\u8ffd\u52a0\u30fb\u524a\u9664\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u51e6\u7406\u3092\u8d70\u3089\u305b\u308b<\/li>\n<li>\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3088\u308bDOM\u66f8\u304d\u63db\u3048\u691c\u77e5<\/li>\n<li>\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u3067\u306e\u5909\u66f4\u8ffd\u8de1<\/li>\n<\/ul>\n<p><strong>\u300cDOM\u306e\u69cb\u9020\u30fb\u5c5e\u6027\u306e\u5909\u5316\u300d\u3092\u30d5\u30c3\u30af\u306b\u4f7f\u3044\u305f\u3044\u5834\u5408<\/strong>\u306b\u6d3b\u8e8d\u3057\u307e\u3059\u3002<\/p>\n<blockquote>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aMutationObserver<\/strong><br \/>\n      DOM\uff08HTML\u69cb\u9020\uff09\u306e\u5909\u66f4\u3092\u691c\u77e5\u3067\u304d\u308bAPI\u3002\u8981\u7d20\u306e\u8ffd\u52a0\u30fb\u524a\u9664\u30fb\u5c5e\u6027\u5909\u66f4\u306a\u3069\u3092\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u76e3\u8996\u3067\u304d\u308b\u3002\n    <\/p>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aDOM\uff08Document Object Model\uff09<\/strong><br \/>\n      HTML\u3084XML\u6587\u66f8\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u64cd\u4f5c\u3059\u308b\u305f\u3081\u306e\u69cb\u9020\u3002\u8981\u7d20\u3084\u5c5e\u6027\u3092\u30c4\u30ea\u30fc\u72b6\u306b\u7ba1\u7406\u3059\u308b\u3002\n    <\/p>\n<\/blockquote>\n<pre><code>const observer = new MutationObserver((mutations) =&gt; {\r\n  console.log('DOM\u304c\u5909\u66f4\u3055\u308c\u307e\u3057\u305f', mutations);\r\n});\r\nobserver.observe(document.body, {\r\n  childList: true,\r\n  subtree: true,\r\n});\r\n<\/code><\/pre>\n<hr \/>\n<h3>3. \u8981\u7d20\u306e\u300c\u30b5\u30a4\u30ba\u5909\u66f4\u300d\u3092\u76e3\u8996\u3059\u308b\uff1a<strong>ResizeObserver<\/strong><\/h3>\n<p>\n    <strong>\u7528\u9014\u4f8b\uff1a<\/strong>\n  <\/p>\n<ul>\n<li>\u30ec\u30b9\u30dd\u30f3\u30b7\u30d6\u30c7\u30b6\u30a4\u30f3\u3067\u306e\u30b5\u30a4\u30ba\u691c\u77e5<\/li>\n<li>\u30c6\u30ad\u30b9\u30c8\u91cf\u306b\u3088\u308b\u30b3\u30f3\u30c6\u30ca\u30b5\u30a4\u30ba\u8ffd\u8de1<\/li>\n<\/ul>\n<p><strong>\u300c\u8981\u7d20\u306e\u5e45\u30fb\u9ad8\u3055\u306e\u5909\u5316\u300d\u306b\u53cd\u5fdc\u3057\u305f\u3044\u6642<\/strong>\u306b\u6700\u9069\u3067\u3059\u3002<\/p>\n<blockquote>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aResizeObserver<\/strong><br \/>\n      \u8981\u7d20\u306e\u30b5\u30a4\u30ba\uff08\u5e45\u30fb\u9ad8\u3055\uff09\u304c\u5909\u5316\u3057\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3092\u691c\u77e5\u3067\u304d\u308bAPI\u3002\u30ec\u30b9\u30dd\u30f3\u30b7\u30d6\u5bfe\u5fdc\u3084\u52d5\u7684\u30ec\u30a4\u30a2\u30a6\u30c8\u306b\u4fbf\u5229\u3002\n    <\/p>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u30ec\u30b9\u30dd\u30f3\u30b7\u30d6\u30c7\u30b6\u30a4\u30f3<\/strong><br \/>\n      \u753b\u9762\u30b5\u30a4\u30ba\u3084\u30c7\u30d0\u30a4\u30b9\u306b\u5fdc\u3058\u3066\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u81ea\u52d5\u8abf\u6574\u3059\u308bWeb\u30c7\u30b6\u30a4\u30f3\u624b\u6cd5\u3002\n    <\/p>\n<\/blockquote>\n<pre><code>const observer = new ResizeObserver((entries) =&gt; {\r\n  for (let entry of entries) {\r\n    const { width, height } = entry.contentRect;\r\n    console.log(`\u8981\u7d20\u306e\u30b5\u30a4\u30ba: ${width}px x ${height}px`);\r\n  }\r\n});\r\nobserver.observe(document.querySelector('#resizable-element'));\r\n<\/code><\/pre>\n<hr \/>\n<h2>3. \u3010\u30b3\u30d4\u30daOK\u3011Intersection Observer\u3067\u753b\u50cf\u306e\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\u3092\u5b9f\u88c5\u3059\u308b\u5168\u624b\u9806<\/h2>\n<p>\u3053\u3053\u304b\u3089\u306f<strong>\u753b\u50cf\u306e\u9045\u5ef6\u8aad\u307f\u8fbc\u307f<\/strong>\u3092\u201c\u3059\u3050\u52d5\u304f\u30b3\u30fc\u30c9\u201d\u3067\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h3>Step1: HTML\u306e\u6e96\u5099\uff08<code>data-*<\/code>\u5c5e\u6027\u3092\u4f7f\u3046\uff09<\/h3>\n<pre><code>&lt;img src=\"placeholder.gif\" data-src=\"real-image.jpg\" alt=\"\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\u3055\u308c\u308b\u753b\u50cf\" class=\"lazyload\"&gt;\r\n&lt;img src=\"placeholder.gif\" data-src=\"real-image-2.jpg\" alt=\"\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\u3055\u308c\u308b\u753b\u50cf\" class=\"lazyload\"&gt;\r\n<\/code><\/pre>\n<blockquote>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1adata-*\u5c5e\u6027<\/strong><br \/>\n      HTML5\u3067\u5c0e\u5165\u3055\u308c\u305f\u3001\u72ec\u81ea\u30c7\u30fc\u30bf\u3092\u8981\u7d20\u306b\u6301\u305f\u305b\u308b\u305f\u3081\u306e\u5c5e\u6027\u3002JavaScript\u304b\u3089\u7c21\u5358\u306b\u53c2\u7167\u30fb\u64cd\u4f5c\u3067\u304d\u308b\u3002\n    <\/p>\n<\/blockquote>\n<h3>Step2: <code>new IntersectionObserver()<\/code>\u3067\u76e3\u8996\u3092\u958b\u59cb<\/h3>\n<pre><code>const options = {\r\n  root: null,\r\n  rootMargin: '0px 0px 100px 0px',\r\n  threshold: 0\r\n};\r\nconst observer = new IntersectionObserver(handleIntersect, options);\r\ndocument.querySelectorAll('.lazyload').forEach(img =&gt; {\r\n  observer.observe(img);\r\n});\r\n<\/code><\/pre>\n<h3>Step3: \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3067\u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f\u51e6\u7406\u3092\u5b9f\u88c5<\/h3>\n<pre><code>function handleIntersect(entries, observer) {\r\n  entries.forEach(entry =&gt; {\r\n    if (entry.isIntersecting) {\r\n      const img = entry.target;\r\n      img.src = img.dataset.src;\r\n      img.classList.remove('lazyload');\r\n      observer.unobserve(img);\r\n    }\r\n  });\r\n}\r\n<\/code><\/pre>\n<h3>Step4: <code>unobserve<\/code>\u3067\u76e3\u8996\u3092\u505c\u6b62\u30fb\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u9632\u6b62<\/h3>\n<p>\n    <strong>\u4e00\u5ea6\u8aad\u307f\u8fbc\u3093\u3060\u753b\u50cf\u306f<code>unobserve()<\/code>\u3067\u76e3\u8996\u89e3\u9664\u3057\u307e\u3057\u3087\u3046\u3002<\/strong><br \/>\n    SPA\u3067\u306f\u7279\u306b\u91cd\u8981\u3067\u3059\u3002\n  <\/p>\n<hr \/>\n<h2>4. \u3010React\u5b9f\u8df5\u7de8\u3011<code>useIntersectionObserver<\/code>\u30ab\u30b9\u30bf\u30e0\u30d5\u30c3\u30af\u3092\u4f5c\u308d\u3046<\/h2>\n<p>React\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3082\u201c\u73fe\u5834\u306b\u5373\u6295\u5165\u3067\u304d\u308b\u201d<strong>\u30ab\u30b9\u30bf\u30e0\u30d5\u30c3\u30af<\/strong>\u4f8b\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\n    \uff08React\u306euseState\u3084useEffect\u306e\u4f7f\u3044\u5206\u3051\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1229\/\" target=\"_blank\" rel=\"noopener\">\u3010\u4fdd\u5b58\u7248\u3011React\u306euseState\u3068useEffect\u306e\u9055\u3044\u3068\u306f\uff1f\u521d\u5fc3\u8005\u304c\u5b9f\u52d9\u3067\u8ff7\u308f\u306a\u3044\u4f7f\u3044\u5206\u3051\u5b8c\u5168\u30ac\u30a4\u30c9<\/a\n    >\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09\n  <\/p>\n<blockquote>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u30ab\u30b9\u30bf\u30e0\u30d5\u30c3\u30af<\/strong><br \/>\n      React\u3067\u72ec\u81ea\u306e\u30ed\u30b8\u30c3\u30af\u3084\u72b6\u614b\u7ba1\u7406\u3092\u518d\u5229\u7528\u53ef\u80fd\u306b\u3059\u308b\u95a2\u6570\u3002use\u25cb\u25cb\u306e\u5f62\u3067\u5b9a\u7fa9\u3059\u308b\u3002\n    <\/p>\n<\/blockquote>\n<h3><code>useRef<\/code>\u3067\u76e3\u8996\u5bfe\u8c61\u3092\u6307\u5b9a\uff0b<code>useEffect<\/code>\u3067\u76e3\u8996\u958b\u59cb\uff0f\u505c\u6b62<\/h3>\n<pre><code>import { useState, useRef, useEffect } from 'react';\r\n\r\nfunction useIntersectionObserver(options) {\r\n  const [entry, setEntry] = useState(null);\r\n  const [node, setNode] = useState(null);\r\n  const observer = useRef(null);\r\n\r\n  useEffect(() =&gt; {\r\n    if (observer.current) observer.current.disconnect();\r\n    observer.current = new IntersectionObserver(([entry]) =&gt; {\r\n      setEntry(entry);\r\n    }, options);\r\n\r\n    const { current: currentObserver } = observer;\r\n    if (node) currentObserver.observe(node);\r\n\r\n    return () =&gt; currentObserver.disconnect();\r\n  }, [node, options]);\r\n\r\n  return [setNode, entry];\r\n}\r\n\r\n\/\/ \u30ab\u30b9\u30bf\u30e0\u30d5\u30c3\u30af\u3092\u4f7f\u3063\u305f\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\r\nfunction LazyImage({ src, alt, placeholderSrc }) {\r\n  const [ref, entry] = useIntersectionObserver({ threshold: 0.1 });\r\n  const [isLoaded, setIsLoaded] = useState(false);\r\n  const isIntersecting = entry ? entry.isIntersecting : false;\r\n\r\n  useEffect(() =&gt; {\r\n    if (isIntersecting && !isLoaded) setIsLoaded(true);\r\n  }, [isIntersecting, isLoaded]);\r\n\r\n  return (\r\n    &lt;img\r\n      ref={ref}\r\n      src={isLoaded ? src : placeholderSrc}\r\n      alt={alt}\r\n      style={{\r\n        transition: 'opacity 0.3s',\r\n        opacity: isLoaded ? 1 : 0.8\r\n      }}\r\n    \/&gt;\r\n  );\r\n}\r\n\/\/ \u4f7f\u7528\u4f8b\r\n\/\/ &lt;LazyImage src=\"real-image.jpg\" placeholderSrc=\"placeholder.gif\" alt=\"React\u3067\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\" \/&gt;\r\n<\/code><\/pre>\n<hr \/>\n<h2>5. FAQ\uff5c\u3088\u304f\u3042\u308b\u7591\u554f\u306b\u56de\u7b54<\/h2>\n<ul>\n<li>\n      <strong>Q1. <code>unobserve()<\/code>\u3092\u547c\u3070\u306a\u3044\u3068\uff1f<\/strong><br \/>A1. \u76e3\u8996\u304c\u6b8b\u308a\u7d9a\u3051\u3001SPA\u3067\u306f<strong>\u30e1\u30e2\u30ea\u30ea\u30fc\u30af<\/strong>\u306e\u6e29\u5e8a\u306b\u306a\u308a\u307e\u3059\u3002\u4e0d\u8981\u306a\u76e3\u8996\u306f\u5fc5\u305a\u89e3\u9664\u3057\u307e\u3057\u3087\u3046\u3002\n    <\/li>\n<li>\n      <strong>Q2. Safari\u3084\u53e4\u3044\u30d6\u30e9\u30a6\u30b6\u5bfe\u5fdc\u306f\uff1f<\/strong><br \/>A2. <strong>IntersectionObserver<\/strong>\u306f\u30e2\u30c0\u30f3\u30d6\u30e9\u30a6\u30b6\u3067\u5e83\u304f\u30b5\u30dd\u30fc\u30c8\u3002<br \/>IE\u7b49\u3067\u306fPolyfill\uff08\u4f8b\uff1a<code>intersection-observer<\/code><br \/>\n      npm\u30d1\u30c3\u30b1\u30fc\u30b8\uff09\u304c\u5fc5\u8981\u3067\u3059\u3002\n    <\/li>\n<li><strong>Q3. \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u304c\u4e00\u5ea6\u3057\u304b\u547c\u3070\u308c\u306a\u3044\uff1f<\/strong><br \/>A3. <code>threshold<\/code>\u3084\u8981\u7d20\u30b5\u30a4\u30ba\u3001\u76e3\u8996\u5bfe\u8c61\u306eCSS\u8a2d\u5b9a\u3092\u898b\u76f4\u3057\u307e\u3057\u3087\u3046\u3002\u9ad8\u30550\u3060\u3068\u4ea4\u5dee\u304c\u691c\u77e5\u3067\u304d\u307e\u305b\u3093\u3002<\/li>\n<li>\n      <strong>Q4. <code>threshold<\/code>\u3092\u914d\u5217\u6307\u5b9a\u3059\u308b\u30e1\u30ea\u30c3\u30c8\u306f\uff1f<\/strong><br \/>A4. \u4f8b\u3048\u3070<code>[0, 0.5, 1]<\/code\n      >\u3068\u3059\u308b\u3068\u3001\u300c\u5c11\u3057\u8868\u793a\u300d\u300c\u534a\u5206\u8868\u793a\u300d\u300c\u5b8c\u5168\u8868\u793a\u300d\u2026\u5404\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3067\u304d\u307e\u3059\u3002\u30ea\u30c3\u30c1\u306a\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306e\u30c8\u30ea\u30ac\u30fc\u306b\u4fbf\u5229\u3067\u3059\u3002\n    <\/li>\n<li>\n      <strong>Q5. TypeScript\u3067\u306e\u578b\u5b9a\u7fa9\u306f\uff1f<\/strong><br \/>A5. <code>IntersectionObserverEntry<\/code>\u3068<code>IntersectionObserver<\/code>\u578b\u3092\u6d3b\u7528\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>const handleIntersect: IntersectionObserverCallback = (\r\n  entries: IntersectionObserverEntry[],\r\n  observer: IntersectionObserver\r\n): void =&gt; { \/* ... *\/ };\r\nconst options: IntersectionObserverInit = { rootMargin: '100px', threshold: 0.1 };\r\nconst observer = new IntersectionObserver(handleIntersect, options);\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u30e1\u30e2\u30ea\u30ea\u30fc\u30af<\/strong><br \/>\n      \u4e0d\u8981\u306b\u306a\u3063\u305f\u30c7\u30fc\u30bf\u3084\u76e3\u8996\u304c\u89e3\u653e\u3055\u308c\u305a\u3001\u30e1\u30e2\u30ea\u3092\u6d88\u8cbb\u3057\u7d9a\u3051\u308b\u73fe\u8c61\u3002SPA\u3084\u9577\u6642\u9593\u7a3c\u50cd\u3059\u308bWeb\u30a2\u30d7\u30ea\u3067\u7279\u306b\u6ce8\u610f\u3002\n    <\/p>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aPolyfill<\/strong><br \/>\n      \u53e4\u3044\u30d6\u30e9\u30a6\u30b6\u3067\u3082\u65b0\u3057\u3044\u6a5f\u80fd\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306e\u88dc\u52a9\u30b9\u30af\u30ea\u30d7\u30c8\u3002\n    <\/p>\n<p>\n      <strong>\u7528\u8a9e\u89e3\u8aac\uff1aTypeScript<\/strong><br \/>\n      JavaScript\u306b\u578b\u5b9a\u7fa9\u3092\u52a0\u3048\u305f\u8a00\u8a9e\u3002\u5927\u898f\u6a21\u958b\u767a\u3084\u4fdd\u5b88\u6027\u5411\u4e0a\u306b\u5f79\u7acb\u3064\u3002\n    <\/p>\n<\/blockquote>\n<hr \/>\n<h2>6. \u307e\u3068\u3081\uff5cObserver\u3092\u4f7f\u3044\u3053\u306a\u3057\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u30d7\u30ed\u3078<\/h2>\n<ul>\n<li><strong>scroll\u30a4\u30d9\u30f3\u30c8\u306e\u5f31\u70b9<\/strong>\u3092\u7406\u89e3\u3057\u3001<\/li>\n<li>3\u7a2e\u306e<strong>Observer API<\/strong>\u306e\u9055\u3044\u3092\u6574\u7406\u3001<\/li>\n<li><strong>IntersectionObserver<\/strong>\u306b\u3088\u308b\u753b\u50cf\u9045\u5ef6\u8aad\u307f\u8fbc\u307f\u306e\u5b9f\u88c5\u30fbReact\u30ab\u30b9\u30bf\u30e0\u30d5\u30c3\u30af\u5316<\/li>\n<\/ul>\n<p>\n    \u307e\u3067\u3001\u4e00\u6c17\u306b\u632f\u308a\u8fd4\u308a\u307e\u3057\u305f\u3002<br \/>\n    \u307e\u305a\u306f<strong>\u52d5\u304f\u30b3\u30fc\u30c9\u3067\u611f\u899a\u3092\u63b4\u307f\u3001\u624b\u5143\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u9069\u7528\u3059\u308b<\/strong>\u3002<br \/>\n    \u3053\u306e\u4e00\u6b69\u304c\u3001<strong>Web\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u3068\u5b9f\u52d9\u529b\u30a2\u30c3\u30d7<\/strong>\u3078\u306e\u9053\u3067\u3059\u3002\n  <\/p>\n<p>\u305c\u3072\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30da\u3057\u3066\u3001\u307e\u305a\u306f\u52d5\u304b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<hr \/>\n<\/div>\n","protected":false},"featured_media":1805,"template":"","_links":{"self":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/route\/1804"}],"collection":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/route"}],"about":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/types\/route"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/media\/1805"}],"wp:attachment":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/media?parent=1804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}