回答編集履歴
4
kakikae
answer
CHANGED
@@ -16,11 +16,11 @@
|
|
16
16
|
var menuHeight=document.querySelector("#menu").getBoundingClientRect().bottom;
|
17
17
|
document.body.scrollTop=top-menuHeight;
|
18
18
|
}
|
19
|
-
window.addEventListener('pageshow',
|
19
|
+
window.addEventListener('pageshow', ()=>{
|
20
20
|
if(location.hash!=="") move();
|
21
|
-
[].forEach.call(document.querySelectorAll('a[href*="#"]'),
|
21
|
+
[].forEach.call(document.querySelectorAll('a[href*="#"]'),x=>{
|
22
22
|
var hash=x.getAttribute("href").match(/#.*$/)[0];
|
23
|
-
x.addEventListener('click',
|
23
|
+
x.addEventListener('click',e=>{
|
24
24
|
e.preventDefault();
|
25
25
|
location.hash=hash;
|
26
26
|
move();
|
3
chouesi
answer
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# sample
|
6
6
|
- fromPage.html
|
7
7
|
```HTML
|
8
|
-
[ <a href="toPage.html#top">top</a> | <a href="toPage.html">target1</a> | <a href="toPage.html">target2</a> ]
|
8
|
+
[ <a href="toPage.html#top">top</a> | <a href="toPage.html#target1">target1</a> | <a href="toPage.html#target2">target2</a> ]
|
9
9
|
```
|
10
10
|
|
11
11
|
- toPage.html
|
2
調整
answer
CHANGED
@@ -3,20 +3,61 @@
|
|
3
3
|
実際にはハッシュで呼び出し位置を調整するくらいですかね
|
4
4
|
|
5
5
|
# sample
|
6
|
+
- fromPage.html
|
6
|
-
```
|
7
|
+
```HTML
|
8
|
+
[ <a href="toPage.html#top">top</a> | <a href="toPage.html">target1</a> | <a href="toPage.html">target2</a> ]
|
9
|
+
```
|
10
|
+
|
11
|
+
- toPage.html
|
12
|
+
```javascript
|
13
|
+
<script>
|
14
|
+
const move=()=>{
|
15
|
+
var top=(document.querySelector(location.hash)||document.querySelector("body")).getBoundingClientRect().top+ window.pageYOffset;
|
16
|
+
var menuHeight=document.querySelector("#menu").getBoundingClientRect().bottom;
|
17
|
+
document.body.scrollTop=top-menuHeight;
|
18
|
+
}
|
19
|
+
window.addEventListener('pageshow', function(e){
|
20
|
+
if(location.hash!=="") move();
|
21
|
+
[].forEach.call(document.querySelectorAll('a[href*="#"]'),function(x){
|
22
|
+
var hash=x.getAttribute("href").match(/#.*$/)[0];
|
23
|
+
x.addEventListener('click',function(e){
|
24
|
+
e.preventDefault();
|
25
|
+
location.hash=hash;
|
26
|
+
move();
|
27
|
+
});
|
28
|
+
});
|
29
|
+
});
|
30
|
+
</script>
|
7
31
|
<style>
|
8
|
-
body{margin:0px;padding:0px;}
|
32
|
+
body,body *{margin:0px;padding:0px;}
|
9
33
|
#menu{height:100px;background-Color:gray;position:fixed;width:100%;}
|
10
34
|
#content{padding-top:100px;height:9999px;}
|
11
35
|
</style>
|
12
36
|
<body>
|
13
|
-
<div id="menu">menu</div>
|
37
|
+
<div id="menu">menu [ <a href="#top">top</a> | <a href="#target1">target1</a> | <a href="#target2">target2</a> ]</div>
|
14
38
|
<div id="content">
|
39
|
+
top<br>
|
15
40
|
row1<br>
|
16
41
|
row2<br>
|
17
42
|
row3<br>
|
18
43
|
row4<br>
|
19
44
|
row5<br>
|
45
|
+
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
|
46
|
+
<a id="target1">target1</a><br>
|
47
|
+
row1<br>
|
48
|
+
row2<br>
|
49
|
+
row3<br>
|
50
|
+
row4<br>
|
51
|
+
row5<br>
|
52
|
+
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
|
53
|
+
<a id="target2">target2</a><br>
|
54
|
+
row1<br>
|
55
|
+
row2<br>
|
56
|
+
row3<br>
|
57
|
+
row4<br>
|
58
|
+
row5<br>
|
20
59
|
</div>
|
60
|
+
</div>
|
21
61
|
</body>
|
62
|
+
|
22
63
|
```
|
1
sample
answer
CHANGED
@@ -1,3 +1,22 @@
|
|
1
1
|
元のページからではjsで飛び先の見え方は指定できないでしょう
|
2
2
|
呼び出し後の適正な見せ方はは飛び先側がやることです。
|
3
|
-
実際にはハッシュで呼び出し位置を調整するくらいですかね
|
3
|
+
実際にはハッシュで呼び出し位置を調整するくらいですかね
|
4
|
+
|
5
|
+
# sample
|
6
|
+
```CSS
|
7
|
+
<style>
|
8
|
+
body{margin:0px;padding:0px;}
|
9
|
+
#menu{height:100px;background-Color:gray;position:fixed;width:100%;}
|
10
|
+
#content{padding-top:100px;height:9999px;}
|
11
|
+
</style>
|
12
|
+
<body>
|
13
|
+
<div id="menu">menu</div>
|
14
|
+
<div id="content">
|
15
|
+
row1<br>
|
16
|
+
row2<br>
|
17
|
+
row3<br>
|
18
|
+
row4<br>
|
19
|
+
row5<br>
|
20
|
+
</div>
|
21
|
+
</body>
|
22
|
+
```
|