- Fixes #596. - Fixes incorrect sidebar scrolling when sidebar has padding-top.
Unified · Split
| @@ -170,10 +170,11 @@ $.scrollTo = (el, parent, position = 'center', options = {}) -> · 169 unmodified lines | ||
| 170 | 170 | return unless parent.scrollHeight > parentHeight |
| 171 | 171 | |
| 172 | 172 | top = $.offset(el, parent).top |
| 173 | + offsetTop = parent.firstElementChild.offsetTop | |
| 173 | 174 | |
| 174 | 175 | switch position |
| 175 | 176 | when 'top' |
| 176 | − parent.scrollTop = top - (if options.margin? then options.margin else 20) | |
| 177 | + parent.scrollTop = top - offsetTop - (if options.margin? then options.margin else 0) | |
| 177 | 178 | when 'center' |
| 178 | 179 | parent.scrollTop = top - Math.round(parentHeight / 2 - el.offsetHeight / 2) |
| 179 | 180 | when 'continuous' |
| @@ -182,8 +183,8 @@ $.scrollTo = (el, parent, position = 'center', options = {}) -> · 2 unmodified lines | ||
| 182 | 183 | |
| 183 | 184 | # If the target element is above the visible portion of its scrollable |
| 184 | 185 | # ancestor, move it near the top with a gap = options.topGap * target's height. |
| 185 | − if top <= scrollTop + height * (options.topGap or 1) | |
| 186 | − parent.scrollTop = top - height * (options.topGap or 1) | |
| 186 | + if top - offsetTop <= scrollTop + height * (options.topGap or 1) | |
| 187 | + parent.scrollTop = top - offsetTop - height * (options.topGap or 1) | |
| 187 | 188 | # If the target element is below the visible portion of its scrollable |
| 188 | 189 | # ancestor, move it near the bottom with a gap = options.bottomGap * target's height. |
| 189 | 190 | else if top >= scrollTop + parentHeight - height * ((options.bottomGap or 1) + 1) |
| @@ -102,7 +102,7 @@ class app.views.Content extends app.View · 101 unmodified lines | ||
| 102 | 102 | return if @isLoading() |
| 103 | 103 | if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash |
| 104 | 104 | $.scrollToWithImageLock el, @scrollEl, 'top', |
| 105 | − margin: 20 + if @scrollEl is @el then 0 else $.offset(@el).top | |
| 105 | + margin: if @scrollEl is @el then 0 else $.offset(@el).top | |
| 106 | 106 | $.highlight el, className: '_highlight' |
| 107 | 107 | else |
| 108 | 108 | @scrollTo @scrollMap[@routeCtx.state.id] |