{"id":1687,"date":"2019-03-07T22:50:11","date_gmt":"2019-03-07T13:50:11","guid":{"rendered":"http:\/\/4koma-web.com\/coding\/?p=1687"},"modified":"2019-03-07T22:51:12","modified_gmt":"2019-03-07T13:51:12","slug":"js%e3%81%a7pcsp%e6%99%82%e3%81%ae%e7%94%bb%e5%83%8f%e3%81%ae%e5%88%87%e3%82%8a%e6%9b%bf%e3%81%88","status":"publish","type":"post","link":"https:\/\/4koma-web.com\/coding\/js%e3%81%a7pcsp%e6%99%82%e3%81%ae%e7%94%bb%e5%83%8f%e3%81%ae%e5%88%87%e3%82%8a%e6%9b%bf%e3%81%88\/","title":{"rendered":"js\u3067pc\/sp\u6642\u306e\u753b\u50cf\u306e\u5207\u308a\u66ff\u3048"},"content":{"rendered":"<p>display:block\/none;\u3067\u306e\u753b\u50cf\u5207\u308a\u66ff\u3048\u3067\u306f\u306a\u304f\u3001\u753b\u50cf\u306e\u30bd\u30fc\u30b9\u3092js\u3067\u5207\u308a\u66ff\u3048\u3066\u8868\u793a\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<br \/>\n\u30b9\u30de\u30db\u30ec\u30a4\u30a2\u30a6\u30c8\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u3001\u3044\u3061\u3044\u3061\u753b\u50cf\u306b\u30af\u30e9\u30b9\u540d\u3092\u4ed8\u4e0e\u3059\u308b\u306e\u304c\u9762\u5012\u306a\u5834\u5408\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<pre>\r\n<img decoding=\"async\" src=\"images\/\u3007\u3007_sp.png\" class=\"change\">\r\n<\/pre>\n<pre>\r\n$(function () {\r\n \/\/\u5909\u6570\u30bb\u30c3\u30c8\r\n var $elem = $('.change');\r\n var sp = '_sp.';\r\n var pc = '_pc.';\r\n var replaceWidth = 768; \r\n \r\n function imageSwitch() {\r\n \r\n var windowWidth = parseInt($(window).width());\r\n \r\n $elem.each(function () {\r\n var $this = $(this);\r\n if (windowWidth >= replaceWidth) {\r\n $this.attr('src', $this.attr('src').replace(sp, pc));\r\n } else {\r\n $this.attr('src', $this.attr('src').replace(pc, sp));\r\n }\r\n });\r\n }\r\n imageSwitch();\r\n \r\n var delayStart;\r\n var delayTime = 200; \/\/\u30df\u30eaSec\r\n $(window).on('resize', function () {\r\n clearTimeout(delayStart);\r\n delayStart = setTimeout(function () {\r\n imageSwitch();\r\n }, delayTime);\r\n });\r\n});\r\n<\/pre>\n<p>\u5207\u308a\u66ff\u3048\u308b\u753b\u50cf\u306f\u753b\u50cf\u306e\u540d\u524d\u306e\u6700\u5f8c\u306b\u3001_pc\u3001_sp\u3068\u3064\u3051\u308b\u3060\u3051\u3067OK\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>display:block\/none;\u3067\u306e\u753b\u50cf\u5207\u308a\u66ff\u3048\u3067\u306f\u306a\u304f\u3001\u753b\u50cf\u306e\u30bd\u30fc\u30b9\u3092js\u3067\u5207\u308a\u66ff\u3048\u3066\u8868\u793a\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002 \u30b9\u30de\u30db\u30ec\u30a4\u30a2\u30a6\u30c8\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u3001\u3044\u3061\u3044\u3061\u753b\u50cf\u306b\u30af\u30e9\u30b9\u540d\u3092\u4ed8\u4e0e\u3059\u308b\u306e\u304c\u9762\u5012\u306a\u5834\u5408\u4fbf\u5229\u3067\u3059\u3002 $(functi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"","_original_post":"","footnotes":""},"categories":[1],"tags":[],"publishpress_future_action":{"enabled":false,"date":"2026-04-21 20:35:31","action":"change-status","newStatus":"draft","terms":[],"taxonomy":"category"},"_links":{"self":[{"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/posts\/1687"}],"collection":[{"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/comments?post=1687"}],"version-history":[{"count":0,"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/posts\/1687\/revisions"}],"wp:attachment":[{"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/media?parent=1687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/categories?post=1687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/4koma-web.com\/coding\/wp-json\/wp\/v2\/tags?post=1687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}