回答編集履歴
1
とりあえず
test
CHANGED
@@ -13,3 +13,141 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
ハッシュの位置に勝手に移動しませんか?
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
# ハッシュの中の指定位置に飛ぶ
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
IEだけ何故かpageshow時のscrollTopが効かないのでsetTimeoutで時間差で処理しました
|
24
|
+
|
25
|
+
- mypage.html
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```HTML
|
30
|
+
|
31
|
+
<ul class="box">
|
32
|
+
|
33
|
+
<li><a href="test.html?target=h4#accordion01">accordion01のh4</a></li>
|
34
|
+
|
35
|
+
<li><a href="test.html?target=.linkbox#accordion01">accordion01の.linkbox</a></li>
|
36
|
+
|
37
|
+
<li><a href="test.html?target=h3#accordion02">accordion02のh3</a></li>
|
38
|
+
|
39
|
+
<li><a href="test.html?target=.linkbox%3Ep#accordion02">accordion02の.linkboxの中のp</a></li>
|
40
|
+
|
41
|
+
</ul>
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
- test.html
|
48
|
+
|
49
|
+
```HTML
|
50
|
+
|
51
|
+
<style>
|
52
|
+
|
53
|
+
.dummy{height:999px;background-Color:gray}
|
54
|
+
|
55
|
+
</style>
|
56
|
+
|
57
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
58
|
+
|
59
|
+
<script>
|
60
|
+
|
61
|
+
$(window).on('pageshow',function(){
|
62
|
+
|
63
|
+
var target=location.search.substring(1).split('&').filter(function(x){
|
64
|
+
|
65
|
+
return x.split('=')[0]=="target";
|
66
|
+
|
67
|
+
}).map(function(x){
|
68
|
+
|
69
|
+
return decodeURIComponent(x.split('=')[1]);
|
70
|
+
|
71
|
+
});
|
72
|
+
|
73
|
+
var t=0;
|
74
|
+
|
75
|
+
if(location.hash.length>0){
|
76
|
+
|
77
|
+
if(target.length>0 && $(location.hash).find(target[0]).length>0){
|
78
|
+
|
79
|
+
t=$(location.hash).find(target[0]).offset().top;
|
80
|
+
|
81
|
+
}else{
|
82
|
+
|
83
|
+
t=$(location.hash).offset().top;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
$(this).scrollTop(t);
|
90
|
+
|
91
|
+
setTimeout(function(){
|
92
|
+
|
93
|
+
$(window).scrollTop(t).dequeue(); //IE対策
|
94
|
+
|
95
|
+
},50);
|
96
|
+
|
97
|
+
});
|
98
|
+
|
99
|
+
</script>
|
100
|
+
|
101
|
+
<div class="dummy"></div>
|
102
|
+
|
103
|
+
<div id="accordion01" class="linkarea">
|
104
|
+
|
105
|
+
<h3>タイトルタイトル</h3>
|
106
|
+
|
107
|
+
<div class="linkbox">
|
108
|
+
|
109
|
+
<h4>リンク1</h4>
|
110
|
+
|
111
|
+
<p>内容内容内容内容内容内容</p>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
|
115
|
+
</div>
|
116
|
+
|
117
|
+
<div class="dummy"></div>
|
118
|
+
|
119
|
+
<div id="accordion02" class="linkarea">
|
120
|
+
|
121
|
+
<h3>タイトルタイトル</h3>
|
122
|
+
|
123
|
+
<div class="linkbox">
|
124
|
+
|
125
|
+
<h4>リンク2</h4>
|
126
|
+
|
127
|
+
<p>内容内容内容内容内容内容</p>
|
128
|
+
|
129
|
+
</div>
|
130
|
+
|
131
|
+
</div>
|
132
|
+
|
133
|
+
<div class="dummy"></div>
|
134
|
+
|
135
|
+
<div id="accordion03" class="linkarea">
|
136
|
+
|
137
|
+
<h3>タイトルタイトル</h3>
|
138
|
+
|
139
|
+
<div class="linkbox">
|
140
|
+
|
141
|
+
<h4>リンク3</h4>
|
142
|
+
|
143
|
+
<p>内容内容内容内容内容内容</p>
|
144
|
+
|
145
|
+
</div>
|
146
|
+
|
147
|
+
</div>
|
148
|
+
|
149
|
+
<div class="dummy"></div>
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
```
|