{"id":6201,"date":"2024-08-03T11:41:15","date_gmt":"2024-08-03T02:41:15","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=6201"},"modified":"2024-05-19T17:56:37","modified_gmt":"2024-05-19T08:56:37","slug":"post-6201","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/6201","title":{"rendered":"JavaScript\u306eIntersectionObserver\u3092\u5229\u7528\u3057\u3066\u6307\u5b9a\u3057\u305f\u8981\u7d20\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u6307\u5b9a\u3057\u305f\u8981\u7d20\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3057\u3001\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u4f55\u3089\u304b\u306e\u30a4\u30d9\u30f3\u30c8\u3092\u5b9f\u884c\u3057\u305f\u3044\u3002JavaScript\u306escroll\u30a4\u30d9\u30f3\u30c8\u3067\u5bfe\u5fdc\u3057\u3088\u3046\u3068\u601d\u3063\u305f\u304c\u3001\u3053\u308c\u3060\u3068\u30b9\u30af\u30ed\u30fc\u30eb\u306e\u5ea6\u306b\u5b9f\u884c\u3055\u308c\u308b\u306e\u3067\u8ca0\u8377\u304c\u304b\u304b\u308b\u3002IntersectionObserver\u3092\u4f7f\u3046\u3053\u3068\u3067\u8ca0\u8377\u8efd\u6e1b\u3067\u304d\u308b\u307f\u305f\u3044\u306a\u306e\u3067\u5b9f\u88c5\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p><a href=\"https:\/\/taitan916.info\/sample\/IntersectionObserver\/\" target=\"_blank\" rel=\"noopener\">https:\/\/taitan916.info\/sample\/IntersectionObserver\/<\/a><\/p>\n<p>\u30b9\u30af\u30ed\u30fc\u30eb\u3057\u3066\u300c\u30bf\u30fc\u30b2\u30c3\u30c8\u300d\u90e8\u5206\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u30da\u30fc\u30b8\u4e0a\u90e8\u304c\u300c\u975e\u8868\u793a\u2192\u8868\u793a\u300d\u306b\u5207\u308a\u66ff\u308f\u308b\u7b48\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u5b9f\u88c5\u65b9\u6cd5<\/h2>\n<h3>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;div class=\"contents\"&gt;\u30b3\u30f3\u30c6\u30f3\u30c4&lt;\/div&gt;\r\n&lt;div class=\"target\"&gt;\u30bf\u30fc\u30b2\u30c3\u30c8&lt;\/div&gt;\r\n&lt;div class=\"contents\"&gt;\u30b3\u30f3\u30c6\u30f3\u30c4&lt;\/div&gt;\r\n&lt;div class=\"check\"&gt;&lt;\/div&gt;\r\n\r\n&lt;script&gt;\r\nconst target = document.querySelector(`.target`);\r\nconst options = {\r\n    root: null, \/\/\u30bf\u30fc\u30b2\u30c3\u30c8\u304c\u898b\u3048\u308b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306e\u30d3\u30e5\u30fc\u30dd\u30fc\u30c8\r\n    rootMargin: `0px`, \/\/root\u306e\u5468\u308a\u306e\u30de\u30fc\u30b8\u30f3\r\n    threshold: 1, \/\/\u30bf\u30fc\u30b2\u30c3\u30c8\u304c\u3069\u306e\u304f\u3089\u3044\u306e\u5272\u5408\u3067\u898b\u3048\u3066\u3044\u308b\u304b\r\n};\r\nconst observer = new IntersectionObserver(displayCheck, options);\r\nobserver.observe(target);\r\n\r\nfunction displayCheck(entries){\r\n    entries.forEach(entry =&gt; {\r\n        const text = ( entry.isIntersecting ) ? `\u8868\u793a` : `\u975e\u8868\u793a`;\r\n        document.querySelector(`.check`).innerText = text;\r\n    });\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/h2>\n<p><a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/API\/IntersectionObserver\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.mozilla.org\/ja\/docs\/Web\/API\/IntersectionObserver<\/a><\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/API\/Intersection_Observer_API\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.mozilla.org\/ja\/docs\/Web\/API\/Intersection_Observer_API<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u6307\u5b9a\u3057\u305f\u8981\u7d20\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3057\u3001\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u4f55\u3089\u304b ... <\/p>\n","protected":false},"author":1,"featured_media":1067,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-6201","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=6201"}],"version-history":[{"count":1,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6201\/revisions"}],"predecessor-version":[{"id":6202,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6201\/revisions\/6202"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1067"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=6201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=6201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=6201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}