回答編集履歴

1

もっとDRYに

2015/11/07 16:55

投稿

退会済みユーザー
test CHANGED
@@ -89,3 +89,93 @@
89
89
  </html>
90
90
 
91
91
  ```
92
+
93
+ ---
94
+
95
+ もっとDRYに
96
+
97
+
98
+
99
+ ```html
100
+
101
+ <!DOCTYPE HTML>
102
+
103
+ <html lang="ja-JP">
104
+
105
+ <head>
106
+
107
+ <meta charset="UTF-8">
108
+
109
+ <title></title>
110
+
111
+ <style type="text/css">
112
+
113
+ .contents {
114
+
115
+ border: 1px solid #CCC;
116
+
117
+ height: 600px;
118
+
119
+ }
120
+
121
+ .animate {
122
+
123
+ background: red;
124
+
125
+ }
126
+
127
+ </style>
128
+
129
+ </head>
130
+
131
+ <body>
132
+
133
+ <div>
134
+
135
+
136
+
137
+ <div class="contents"></div>
138
+
139
+ <div class="contents"></div>
140
+
141
+ <div class="contents"></div>
142
+
143
+
144
+
145
+ </div>
146
+
147
+ <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
148
+
149
+ <script type="text/javascript">
150
+
151
+ $(function () {
152
+
153
+ $(window).scroll(function () {
154
+
155
+ var selectors = $('.contents');
156
+
157
+ var scroll = $(window).scrollTop();
158
+
159
+ selectors.each(function () {
160
+
161
+ var position = $(this).offset().top - $(window).height();
162
+
163
+ if (position < scroll) {
164
+
165
+ $(this).addClass("animate");
166
+
167
+ }
168
+
169
+ });
170
+
171
+ });
172
+
173
+ });
174
+
175
+ </script>
176
+
177
+ </body>
178
+
179
+ </html>
180
+
181
+ ```