Skip to content

Commit c29c54e

Browse files
authoredAug 7, 2020
Merge pull request #106 from telerik/scroll-bug-from-top
fix: Incorrect scroll offset on initial page load and when starting from the top
2 parents e68830b + 12279ac commit c29c54e

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed
 

‎_assets/js/api-toc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $(function () {
1313
if (!!initialHash) {
1414
setTimeout(function(){
1515
animateScrolling(initialHash);
16-
}, 100);
16+
}, 200);
1717
}
1818

1919
$("#markdown-toc")

‎_assets/js/toc-base.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
function animateScrolling(hash) {
2+
var isApiSection = $("article.api-reference").length == 1;
3+
var breadCrumbsElement = $("p.breadcrumbs");
4+
var hasBreadCrumbs = breadCrumbsElement.length == 1 && breadCrumbsElement.text().trim() != "";
25
var currentScrollTop = $(window).scrollTop();
36
var offset = $(hash).offset() || { top: currentScrollTop };
4-
var scrollOffsetCorrection = currentScrollTop == 0 ? HEADER_HEIGHT + NAVBAR_HEIGHT : NAVBAR_HEIGHT;
7+
8+
var scrollOffsetCorrection = NAVBAR_HEIGHT;
9+
if (currentScrollTop == 0) {
10+
scrollOffsetCorrection += HEADER_HEIGHT;
11+
if (hasBreadCrumbs) {
12+
scrollOffsetCorrection += BREADCRUMBS_HEIGHT;
13+
}
14+
if (isApiSection) {
15+
scrollOffsetCorrection += API_SCROLL_FIX;
16+
}
17+
}
518

619
$('html, body').animate({
720
scrollTop: offset.top - scrollOffsetCorrection

‎_assets/js/toc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ $(function() {
5858
if (!!initialHash) {
5959
setTimeout(function(){
6060
animateScrolling(initialHash);
61-
}, 100);
61+
}, 200);
6262
}
6363

6464
// animated scroll

‎_assets/js/top-menu.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
var HEADER_HEIGHT = 100;
1+
var HEADER_HEIGHT = 81;
22
var TELERIKBAR_HEIGHT = 70;
33
var NAVBAR_HEIGHT = 76;
4+
var BREADCRUMBS_HEIGHT = 20;
5+
var API_SCROLL_FIX = 40;
46
var SCROLLSPY_OFFSET = TELERIKBAR_HEIGHT + 10; // 10 compensates for the space above the anchored heading
57
var FOOTER_DISTANCE = 20;
68
var windowHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);

0 commit comments

Comments
 (0)