回答編集履歴
1
HTML追記
test
CHANGED
@@ -5,3 +5,127 @@
|
|
5
5
|
$nav = $('thead'),
|
6
6
|
|
7
7
|
```
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
-- HTML追記
|
12
|
+
|
13
|
+
```HTML
|
14
|
+
|
15
|
+
<!DOCTYPE html>
|
16
|
+
|
17
|
+
<html>
|
18
|
+
|
19
|
+
<head><meta charset="UTF-8" /><title>title</title>
|
20
|
+
|
21
|
+
<style>
|
22
|
+
|
23
|
+
.is-fixed {
|
24
|
+
|
25
|
+
position: fixed;
|
26
|
+
|
27
|
+
top: 0;
|
28
|
+
|
29
|
+
left: 0;
|
30
|
+
|
31
|
+
z-index: 2;
|
32
|
+
|
33
|
+
width: 100%;
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
</style>
|
38
|
+
|
39
|
+
</head>
|
40
|
+
|
41
|
+
<body>
|
42
|
+
|
43
|
+
<table>
|
44
|
+
|
45
|
+
<thead>
|
46
|
+
|
47
|
+
<tr>
|
48
|
+
|
49
|
+
<th>id</th>
|
50
|
+
|
51
|
+
<th>タイトル</th>
|
52
|
+
|
53
|
+
</tr>
|
54
|
+
|
55
|
+
</thead>
|
56
|
+
|
57
|
+
<tbody>
|
58
|
+
|
59
|
+
<tr>
|
60
|
+
|
61
|
+
<td>1</td>
|
62
|
+
|
63
|
+
<td>プログラミング全般</td>
|
64
|
+
|
65
|
+
</tr>
|
66
|
+
|
67
|
+
<tr>
|
68
|
+
|
69
|
+
<td>2</td>
|
70
|
+
|
71
|
+
<td>PHP</td>
|
72
|
+
|
73
|
+
</tr>
|
74
|
+
|
75
|
+
</tbody>
|
76
|
+
|
77
|
+
</table>
|
78
|
+
|
79
|
+
<main style="height:200vh"><p>main</p></main>
|
80
|
+
|
81
|
+
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
82
|
+
|
83
|
+
<script>
|
84
|
+
|
85
|
+
$(function() {
|
86
|
+
|
87
|
+
var $win = $(window),
|
88
|
+
|
89
|
+
$main = $('main'),
|
90
|
+
|
91
|
+
$nav = $('thead'),
|
92
|
+
|
93
|
+
navHeight = $nav.outerHeight(),
|
94
|
+
|
95
|
+
navPos = $nav.offset().top,
|
96
|
+
|
97
|
+
fixedClass = 'is-fixed';
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
$win.on('load scroll', function() {
|
102
|
+
|
103
|
+
var value = $(this).scrollTop();
|
104
|
+
|
105
|
+
if ( value > navPos ) {
|
106
|
+
|
107
|
+
$nav.addClass(fixedClass);
|
108
|
+
|
109
|
+
$main.css('margin-top', navHeight);
|
110
|
+
|
111
|
+
console.log("動作せず")
|
112
|
+
|
113
|
+
} else {
|
114
|
+
|
115
|
+
$nav.removeClass(fixedClass);
|
116
|
+
|
117
|
+
$main.css('margin-top', '0');
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
});
|
122
|
+
|
123
|
+
});
|
124
|
+
|
125
|
+
</script>
|
126
|
+
|
127
|
+
</body>
|
128
|
+
|
129
|
+
</html>
|
130
|
+
|
131
|
+
```
|