回答編集履歴
1
もっとDRYに
answer
CHANGED
@@ -43,4 +43,49 @@
|
|
43
43
|
</script>
|
44
44
|
</body>
|
45
45
|
</html>
|
46
|
+
```
|
47
|
+
---
|
48
|
+
もっとDRYに
|
49
|
+
|
50
|
+
```html
|
51
|
+
<!DOCTYPE HTML>
|
52
|
+
<html lang="ja-JP">
|
53
|
+
<head>
|
54
|
+
<meta charset="UTF-8">
|
55
|
+
<title></title>
|
56
|
+
<style type="text/css">
|
57
|
+
.contents {
|
58
|
+
border: 1px solid #CCC;
|
59
|
+
height: 600px;
|
60
|
+
}
|
61
|
+
.animate {
|
62
|
+
background: red;
|
63
|
+
}
|
64
|
+
</style>
|
65
|
+
</head>
|
66
|
+
<body>
|
67
|
+
<div>
|
68
|
+
|
69
|
+
<div class="contents"></div>
|
70
|
+
<div class="contents"></div>
|
71
|
+
<div class="contents"></div>
|
72
|
+
|
73
|
+
</div>
|
74
|
+
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
|
75
|
+
<script type="text/javascript">
|
76
|
+
$(function () {
|
77
|
+
$(window).scroll(function () {
|
78
|
+
var selectors = $('.contents');
|
79
|
+
var scroll = $(window).scrollTop();
|
80
|
+
selectors.each(function () {
|
81
|
+
var position = $(this).offset().top - $(window).height();
|
82
|
+
if (position < scroll) {
|
83
|
+
$(this).addClass("animate");
|
84
|
+
}
|
85
|
+
});
|
86
|
+
});
|
87
|
+
});
|
88
|
+
</script>
|
89
|
+
</body>
|
90
|
+
</html>
|
46
91
|
```
|