回答編集履歴
4
kakikae
test
CHANGED
@@ -34,15 +34,15 @@
|
|
34
34
|
|
35
35
|
}
|
36
36
|
|
37
|
-
window.addEventListener('pageshow',
|
37
|
+
window.addEventListener('pageshow', ()=>{
|
38
38
|
|
39
39
|
if(location.hash!=="") move();
|
40
40
|
|
41
|
-
[].forEach.call(document.querySelectorAll('a[href*="#"]'),
|
41
|
+
[].forEach.call(document.querySelectorAll('a[href*="#"]'),x=>{
|
42
42
|
|
43
43
|
var hash=x.getAttribute("href").match(/#.*$/)[0];
|
44
44
|
|
45
|
-
x.addEventListener('click',
|
45
|
+
x.addEventListener('click',e=>{
|
46
46
|
|
47
47
|
e.preventDefault();
|
48
48
|
|
3
chouesi
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
```HTML
|
14
14
|
|
15
|
-
[ <a href="toPage.html#top">top</a> | <a href="toPage.html">target1</a> | <a href="toPage.html">target2</a> ]
|
15
|
+
[ <a href="toPage.html#top">top</a> | <a href="toPage.html#target1">target1</a> | <a href="toPage.html#target2">target2</a> ]
|
16
16
|
|
17
17
|
```
|
18
18
|
|
2
調整
test
CHANGED
@@ -8,11 +8,59 @@
|
|
8
8
|
|
9
9
|
# sample
|
10
10
|
|
11
|
+
- fromPage.html
|
12
|
+
|
11
|
-
```
|
13
|
+
```HTML
|
14
|
+
|
15
|
+
[ <a href="toPage.html#top">top</a> | <a href="toPage.html">target1</a> | <a href="toPage.html">target2</a> ]
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
- toPage.html
|
22
|
+
|
23
|
+
```javascript
|
24
|
+
|
25
|
+
<script>
|
26
|
+
|
27
|
+
const move=()=>{
|
28
|
+
|
29
|
+
var top=(document.querySelector(location.hash)||document.querySelector("body")).getBoundingClientRect().top+ window.pageYOffset;
|
30
|
+
|
31
|
+
var menuHeight=document.querySelector("#menu").getBoundingClientRect().bottom;
|
32
|
+
|
33
|
+
document.body.scrollTop=top-menuHeight;
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
window.addEventListener('pageshow', function(e){
|
38
|
+
|
39
|
+
if(location.hash!=="") move();
|
40
|
+
|
41
|
+
[].forEach.call(document.querySelectorAll('a[href*="#"]'),function(x){
|
42
|
+
|
43
|
+
var hash=x.getAttribute("href").match(/#.*$/)[0];
|
44
|
+
|
45
|
+
x.addEventListener('click',function(e){
|
46
|
+
|
47
|
+
e.preventDefault();
|
48
|
+
|
49
|
+
location.hash=hash;
|
50
|
+
|
51
|
+
move();
|
52
|
+
|
53
|
+
});
|
54
|
+
|
55
|
+
});
|
56
|
+
|
57
|
+
});
|
58
|
+
|
59
|
+
</script>
|
12
60
|
|
13
61
|
<style>
|
14
62
|
|
15
|
-
body{margin:0px;padding:0px;}
|
63
|
+
body,body *{margin:0px;padding:0px;}
|
16
64
|
|
17
65
|
#menu{height:100px;background-Color:gray;position:fixed;width:100%;}
|
18
66
|
|
@@ -22,9 +70,39 @@
|
|
22
70
|
|
23
71
|
<body>
|
24
72
|
|
25
|
-
<div id="menu">menu</div>
|
73
|
+
<div id="menu">menu [ <a href="#top">top</a> | <a href="#target1">target1</a> | <a href="#target2">target2</a> ]</div>
|
26
74
|
|
27
75
|
<div id="content">
|
76
|
+
|
77
|
+
top<br>
|
78
|
+
|
79
|
+
row1<br>
|
80
|
+
|
81
|
+
row2<br>
|
82
|
+
|
83
|
+
row3<br>
|
84
|
+
|
85
|
+
row4<br>
|
86
|
+
|
87
|
+
row5<br>
|
88
|
+
|
89
|
+
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
|
90
|
+
|
91
|
+
<a id="target1">target1</a><br>
|
92
|
+
|
93
|
+
row1<br>
|
94
|
+
|
95
|
+
row2<br>
|
96
|
+
|
97
|
+
row3<br>
|
98
|
+
|
99
|
+
row4<br>
|
100
|
+
|
101
|
+
row5<br>
|
102
|
+
|
103
|
+
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
|
104
|
+
|
105
|
+
<a id="target2">target2</a><br>
|
28
106
|
|
29
107
|
row1<br>
|
30
108
|
|
@@ -38,6 +116,10 @@
|
|
38
116
|
|
39
117
|
</div>
|
40
118
|
|
119
|
+
</div>
|
120
|
+
|
41
121
|
</body>
|
42
122
|
|
123
|
+
|
124
|
+
|
43
125
|
```
|
1
sample
test
CHANGED
@@ -3,3 +3,41 @@
|
|
3
3
|
呼び出し後の適正な見せ方はは飛び先側がやることです。
|
4
4
|
|
5
5
|
実際にはハッシュで呼び出し位置を調整するくらいですかね
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
# sample
|
10
|
+
|
11
|
+
```CSS
|
12
|
+
|
13
|
+
<style>
|
14
|
+
|
15
|
+
body{margin:0px;padding:0px;}
|
16
|
+
|
17
|
+
#menu{height:100px;background-Color:gray;position:fixed;width:100%;}
|
18
|
+
|
19
|
+
#content{padding-top:100px;height:9999px;}
|
20
|
+
|
21
|
+
</style>
|
22
|
+
|
23
|
+
<body>
|
24
|
+
|
25
|
+
<div id="menu">menu</div>
|
26
|
+
|
27
|
+
<div id="content">
|
28
|
+
|
29
|
+
row1<br>
|
30
|
+
|
31
|
+
row2<br>
|
32
|
+
|
33
|
+
row3<br>
|
34
|
+
|
35
|
+
row4<br>
|
36
|
+
|
37
|
+
row5<br>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
</body>
|
42
|
+
|
43
|
+
```
|