|
17 | 17 | // close prepare |
18 | 18 | closeNoHighlightResolvedThread(); |
19 | 19 |
|
20 | | - // scroll to latest |
21 | | - await scrollToHighlight(); |
22 | | - |
23 | 20 | // add highlight indicator |
24 | 21 | addHighlightIndicator(); |
| 22 | + |
| 23 | + // scroll to latest |
| 24 | + await scrollToHighlight(); |
25 | 25 | } |
26 | 26 |
|
27 | 27 | function getComments() { |
|
160 | 160 | indicatorEl.appendChild(currentPosEl); |
161 | 161 |
|
162 | 162 | // calc timeline height |
163 | | - const lastCommentBottom = getComments().pop().getBoundingClientRect().bottom; |
164 | | - const timelineRect = document.querySelector('.js-discussion').getBoundingClientRect(); |
165 | | - const timelineHeight = timelineRect.height - (timelineRect.bottom - lastCommentBottom); |
| 163 | + function getTimelineHeight() { |
| 164 | + const lastCommentBottom = getComments().pop().getBoundingClientRect().bottom + window.scrollY; |
| 165 | + const timelineRect = document.querySelector('.js-discussion').getBoundingClientRect(); |
| 166 | + const timelineBottom = timelineRect.bottom + window.scrollY; |
| 167 | + const timelineHeight = timelineRect.height - (timelineBottom - lastCommentBottom); |
| 168 | + return {timelineHeight, timelineRect}; |
| 169 | + } |
| 170 | + const {timelineHeight, timelineRect} = getTimelineHeight(); |
166 | 171 | const timelineOffset = timelineRect.top + window.pageYOffset; //.js-discussionのheightを使うために、commentの絶対位置をオフセットする必要がある |
167 | 172 |
|
168 | 173 | // タイムラインの高さが小さいときは、インジケータも小さくする |
|
218 | 223 | // scroll position |
219 | 224 | if (timelineRect.bottom > window.innerHeight) { |
220 | 225 | window.addEventListener('wheel', async () => { |
221 | | - const top = Math.max(0, window.scrollY - timelineRect.top); |
222 | | - const bottom = Math.min(timelineHeight, (window.scrollY + window.innerHeight) - timelineRect.top); |
| 226 | + const windowTop = window.scrollY; |
| 227 | + const windowBottom = window.scrollY + window.innerHeight; |
| 228 | + const {timelineHeight, timelineRect} = getTimelineHeight(); |
| 229 | + const timelineTop = timelineRect.top + window.scrollY; |
| 230 | + const top = Math.min(timelineHeight, Math.max(0, windowTop - timelineTop)); |
| 231 | + const bottom = Math.max(0, Math.min(timelineHeight, windowBottom - timelineTop)); |
223 | 232 | const height = (bottom - top) / timelineHeight; |
224 | | - // if (Math.ceil(100 * height) >= 100) return; |
225 | 233 |
|
226 | 234 | currentPosEl.style.top = `${top/timelineHeight * 100}%`; |
227 | 235 | currentPosEl.style.height = `${height * 100}%`; |
|
0 commit comments