Skip to content

Commit

Permalink
Fix a weird stick at top when scrolling bug (#376)
Browse files Browse the repository at this point in the history
For reasons unknown, getting the width of the stuck element by calling $el.width() _after_ adding the shim to the document causes Chrome 56 to scroll down by the height of the shim, effectively ‘jumping’ the user down the document.

This behaviour does not occur in other browsers, nor did it occur in Chrome 55.

Somehow, this fixes it.

¯\_(ツ)_/¯
  • Loading branch information
36degrees authored and robinwhittleton committed Jan 30, 2017
1 parent d15e738 commit 05c5d02
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions javascripts/govuk/stick-at-top-when-scrolling.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@
if (!$el.hasClass('content-fixed')) {
$el.data('scrolled-from', sticky.getElementOffset($el).top)
var height = Math.max($el.height(), 1)
$el.before('<div class="shim" style="width: ' + $el.width() + 'px; height: ' + height + 'px">&nbsp;</div>')
$el.css('width', $el.width() + 'px').addClass('content-fixed')
var width = $el.width()
$el.before('<div class="shim" style="width: ' + width + 'px; height: ' + height + 'px">&nbsp;</div>')
$el.css('width', width + 'px').addClass('content-fixed')
}
},
release: function ($el) {
Expand Down

0 comments on commit 05c5d02

Please sign in to comment.