{"id":568,"date":"2017-03-23T12:01:12","date_gmt":"2017-03-23T03:01:12","guid":{"rendered":"http:\/\/www.takaya-com.jp\/archives\/?p=568"},"modified":"2017-03-23T13:01:55","modified_gmt":"2017-03-23T04:01:55","slug":"scroll_effect","status":"publish","type":"post","link":"https:\/\/takaya-com.jp\/archives\/2017\/03\/scroll_effect\/","title":{"rendered":"jQuery\u3068CSS\u3067\u30b9\u30af\u30ed\u30fc\u30eb\u30a8\u30d5\u30a7\u30af\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f"},"content":{"rendered":"<p>\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u53ef\u8996\u7bc4\u56f2\u306b\u5165\u308b\u3068\u3001\u3075\u308f\u3063\u3068\u6d6e\u304b\u3093\u3067\u304f\u308b\u30b9\u30af\u30ed\u30fc\u30eb\u30a8\u30d5\u30a7\u30af\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u2193\u4ee5\u4e0b\u304c\u5b9f\u969b\u306e\u30bd\u30fc\u30b9\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<p>\u25bcJavaScript<\/p>\n<pre class=\"lang:js decode:true \" >&lt;script&gt;\r\n$(function(){\r\n\t$(\".effect div,.effect img\").css(\"opacity\",\"0\");\r\n\t$(window).scroll(function (){\r\n\t\t$(\".effect\").each(function(){\r\n\t\tvar imgPos = $(this).offset().top;\r\n\t\tvar scroll = $(window).scrollTop();\r\n\t\tvar windowHeight = $(window).height();\r\n\t\tif (scroll &gt; imgPos - windowHeight + windowHeight\/5){\r\n\t\t\t$(\"div,img\",this).css(\"opacity\",\"1\" );\r\n\t\t\t$(\"img\",this).css({ \r\n\t\t\t\t\"margin-top\": \"0px\"\r\n\t\t\t});\r\n\t\t}\r\n\t\telse {\r\n\t\t\t$(\"div,img\",this).css(\"opacity\",\"0\" );\r\n\t\t\t$(\"img\",this).css({ \r\n\t\t\t\t\"margin-top\": \"30px\"\r\n\t\t\t});\r\n\t\t}\r\n\t\t});\r\n\t});\r\n});\r\n&lt;\/script&gt;<\/pre>\n<p>\u25bcCSS <\/p>\n<pre class=\"lang:css decode:true \" >&lt;style&gt;\r\n\thtml, body {\r\n\t\theight: 100%;\r\n\t}\r\n\tbody {\r\n\t\tmargin: 0;\r\n\t\tcolor: #23001E;\r\n\t}\r\n\tsection {\r\n\t\twidth: 100%;\r\n\t\theight: 100%;\r\n\t\ttext-align: center;\r\n\t\tposition: relative;\r\n\t}\r\n\th2{\r\n\t\twidth: 200px;\r\n\t\tborder: 1px solid #23001E;\r\n\t\tpadding: 10px;\r\n\t}\r\n\tp {\r\n\t\twidth: 200px;\r\n\t\tpadding: 10px;\r\n\t}\r\n\t.fixed {\r\n\t\tposition: fixed;\r\n\t\ttop: 0;\r\n\t\tbottom: 0;\r\n\t\tleft: 0;\r\n\t\tright: 0;\r\n\t\tmargin: auto;\r\n\t\twidth: 200px;\r\n\t\theight: 200px;\r\n\t}\r\n\t.absolute {\r\n\t\tposition: absolute;\r\n\t\ttop: 0;\r\n\t\tbottom: 0;\r\n\t\tleft: 0;\r\n\t\tright: 0;\r\n\t\tmargin: auto;\r\n\t\twidth: 200px;\r\n\t\theight: 100px;\r\n\t}\r\n\timg {\r\n\t\tmargin-left: -50px;\r\n\t\tmargin-top: 30px;\r\n\t}\r\n\t#section1 {\r\n\t\tbackground-color: #BCB382;\r\n\t}\r\n\t#section2 {\r\n\t\tbackground-color: #A4A9AD;\r\n\t}\r\n\t#section3 {\r\n\t\tbackground-color: #F6E27F;\r\n\t}\r\n\t#section3 .absolute {\r\n\t\theight: 400px;\r\n\t}\r\n\t.effect div {\r\n\t\tmargin: auto;\r\n\t\ttransition: 1s;\r\n\t}\r\n\t.effect img {\r\n\t\ttransition: 1s;\r\n\t\ttransition-delay: 1s;\r\n\t}\r\n&lt;\/style&gt;<\/pre>\n<p>\u25bcHTML<\/p>\n<pre class=\"lang:xhtml decode:true \" >&lt;section id=\"section1\"&gt;\r\n\t&lt;div class=\"fixed\"&gt;\r\n\t\t&lt;h2&gt;Section1&lt;\/h2&gt;\r\n\t\t\t&lt;p&gt;\u30b9\u30af\u30ed\u30fc\u30eb\u3059\u308b\u3068\u30c6\u30ad\u30b9\u30c8\u304c\u3075\u308f\u3063\u3068\u73fe\u308c\u307e\u3059\u3002&lt;\/p&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/section&gt;\r\n&lt;section id=\"section2\"&gt;\r\n\t&lt;div class=\"absolute effect\"&gt;\r\n\t\t&lt;div&gt;\r\n\t\t\t&lt;h2&gt;Section2&lt;\/h2&gt;\r\n\t\t&lt;\/div&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/section&gt;\r\n&lt;section id=\"section3\"&gt;\r\n\t&lt;div class=\"absolute effect\"&gt;\r\n\t\t&lt;div&gt;\r\n\t\t\t&lt;h2&gt;Section3&lt;\/h2&gt;\r\n\t\t\t&lt;p&gt;\u5c11\u3057\u4e0b\u304b\u3089\u753b\u50cf\u304c\u3075\u308f\u3063\u3068\u73fe\u308c\u307e\u3059\u3002&lt;\/p&gt;\r\n\t\t&lt;\/div&gt;\r\n\t\t\t&lt;img src=\"cat.jpg\" alt=\"\u306d\u3053\"&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/section&gt;<\/pre>\n<p>\u4eca\u56de\u3001\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u306e\u306f\u3001<br \/>\n\u300e<a href=\"http:\/\/weboook.blog22.fc2.com\/blog-entry-415.html\" target=\"_blank\">jQuery\u3068CSS\u306etransition\u3067\u53ef\u8996\u7bc4\u56f2\u306b\u5165\u3063\u3066\u304b\u3089\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u308b\u65b9\u6cd5\uff5cWebpark<\/a>\u300f\u3055\u3093\u3067\u3059\u3002<br \/>\n\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/www.takaya-com.jp\/archives\/demo\/scroll_effect\/\" target=\"_blank\">\u30c7\u30e2\u30da\u30fc\u30b8\u306f\u3001\u3053\u3061\u3089<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u53ef\u8996\u7bc4\u56f2\u306b\u5165\u308b\u3068\u3001\u3075\u308f\u3063\u3068\u6d6e\u304b\u3093\u3067\u304f\u308b\u30b9\u30af\u30ed\u30fc\u30eb\u30a8\u30d5\u30a7\u30af\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/568"}],"collection":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/comments?post=568"}],"version-history":[{"count":4,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/568\/revisions"}],"predecessor-version":[{"id":572,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/568\/revisions\/572"}],"wp:attachment":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/media?parent=568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/categories?post=568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/tags?post=568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}