回答編集履歴
3
getSidebarWidthStyle適用箇所修正
test
CHANGED
@@ -112,7 +112,7 @@
|
|
112
112
|
|
113
113
|
top: "10px",
|
114
114
|
|
115
|
-
width:
|
115
|
+
width: getSidebarWidthStyle() // ここを変更
|
116
116
|
|
117
117
|
});
|
118
118
|
|
@@ -126,7 +126,7 @@
|
|
126
126
|
|
127
127
|
top: "auto",
|
128
128
|
|
129
|
-
width:
|
129
|
+
width: "100%"
|
130
130
|
|
131
131
|
});
|
132
132
|
|
2
フルver\.のサンプルコード追加
test
CHANGED
@@ -62,6 +62,114 @@
|
|
62
62
|
|
63
63
|
|
64
64
|
|
65
|
+
フルだとこんなかんじかな
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
// サイドバースクロール
|
70
|
+
|
71
|
+
$(function() {
|
72
|
+
|
73
|
+
var target = $(".fixnav");
|
74
|
+
|
75
|
+
var footer = $("footer")
|
76
|
+
|
77
|
+
var targetHeight = target.outerHeight(true);
|
78
|
+
|
79
|
+
var targetTop = target.offset().top;
|
65
80
|
|
66
81
|
|
67
82
|
|
83
|
+
$(window).scroll(function() {
|
84
|
+
|
85
|
+
var scrollTop = $(this).scrollTop();
|
86
|
+
|
87
|
+
if (scrollTop > targetTop) {
|
88
|
+
|
89
|
+
// 動的にコンテンツが追加されてもいいように、常に計算する
|
90
|
+
|
91
|
+
var footerTop = footer.offset().top;
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
if (scrollTop + targetHeight > footerTop) {
|
96
|
+
|
97
|
+
customTopPosition = footerTop - (scrollTop + targetHeight)
|
98
|
+
|
99
|
+
target.css({
|
100
|
+
|
101
|
+
position: "fixed",
|
102
|
+
|
103
|
+
top: customTopPosition + "px"
|
104
|
+
|
105
|
+
});
|
106
|
+
|
107
|
+
} else {
|
108
|
+
|
109
|
+
target.css({
|
110
|
+
|
111
|
+
position: "fixed",
|
112
|
+
|
113
|
+
top: "10px",
|
114
|
+
|
115
|
+
width: "14.6%"
|
116
|
+
|
117
|
+
});
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
} else {
|
122
|
+
|
123
|
+
target.css({
|
124
|
+
|
125
|
+
position: "relative",
|
126
|
+
|
127
|
+
top: "auto",
|
128
|
+
|
129
|
+
width: getSidebarWidthStyle() // ここを変更
|
130
|
+
|
131
|
+
});
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
});
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
// ここから追加
|
140
|
+
|
141
|
+
function getSidebarWidthStyle(){
|
142
|
+
|
143
|
+
var windowWidth = window.innerWidth;
|
144
|
+
|
145
|
+
if(windowWidth < 768){
|
146
|
+
|
147
|
+
// Small devices
|
148
|
+
|
149
|
+
return "80px"
|
150
|
+
|
151
|
+
}else if(windowWidth < 992){
|
152
|
+
|
153
|
+
// Medium devices
|
154
|
+
|
155
|
+
return "25.0%"
|
156
|
+
|
157
|
+
}else){
|
158
|
+
|
159
|
+
// More Larger
|
160
|
+
|
161
|
+
return "14.6%"
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
});
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
1
実装イメージ追加
test
CHANGED
@@ -1 +1,67 @@
|
|
1
1
|
window.innerWidthの値次第で分岐させてはどうでしょうか?
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
イメージこんなかんじです
|
6
|
+
|
7
|
+
```
|
8
|
+
|
9
|
+
target.css({
|
10
|
+
|
11
|
+
position: "fixed",
|
12
|
+
|
13
|
+
top: customTopPosition + "px"
|
14
|
+
|
15
|
+
});
|
16
|
+
|
17
|
+
} else {
|
18
|
+
|
19
|
+
target.css({
|
20
|
+
|
21
|
+
position: "fixed",
|
22
|
+
|
23
|
+
top: "10px",
|
24
|
+
|
25
|
+
width: getSidebarWidthStyle()
|
26
|
+
|
27
|
+
});
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
function getSidebarWidthStyle(){
|
36
|
+
|
37
|
+
var windowWidth = window.innerWidth;
|
38
|
+
|
39
|
+
if(windowWidth < 768){
|
40
|
+
|
41
|
+
// Small devices
|
42
|
+
|
43
|
+
return "80px"
|
44
|
+
|
45
|
+
}else if(windowWidth < 992){
|
46
|
+
|
47
|
+
// Medium devices
|
48
|
+
|
49
|
+
return "25.0%"
|
50
|
+
|
51
|
+
}else){
|
52
|
+
|
53
|
+
// More Larger
|
54
|
+
|
55
|
+
return "14.6%"
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|