Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #565 from abbeyj/scroll-to-anchor
Browse files Browse the repository at this point in the history
Fix scrolling to selected line on page load in Chrome.
  • Loading branch information
erikrose committed Jun 17, 2016
2 parents 6d22db5 + d27781d commit 248e4ac
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions dxr/static_unhashed/js/code-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,16 @@ $(function () {
//for directly linked line(s), scroll to the offset minus 150px for fixed search bar height
//but only scrollTo if the offset is more than 150px in distance from the top of the page
jumpPosition = parseInt(jumpPosition.top, 10) - 150;
if (jumpPosition >= 0) {
window.scrollTo(0, jumpPosition);
} else {
window.scrollTo(0, 0);
if (jumpPosition < 0) {
jumpPosition = 0;
}

// Trying to scroll in the document ready handler doesn't work because some
// browsers (e.g. Chrome) will reset the scroll position later.
// Delaying the scroll with setTimeout works around this problem.
window.setTimeout(function() {
window.scrollTo(0, jumpPosition);
}, 0);
//tidy up an incoming url that might be typed in manually
setWindowHash();
}
Expand Down

0 comments on commit 248e4ac

Please sign in to comment.