Skip to content

Commit ed3ff30

Browse files
committed
Fix issue with the position of the search results after scrolling the page
Previously, if the user scrolled down a page on desktop and the black breadcrumb bar moved to the top, the search results pane would not have the correct height.
1 parent 0f11ce1 commit ed3ff30

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

static/canjs.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ var $articleContainer,
7272
}, 50));
7373

7474
// toggle nav on interval instead of scroll to prevent queueing issues
75-
setInterval(function() {
76-
toggleNav();
77-
}, 200);
75+
if (!isMobile()) {
76+
setInterval(function() {
77+
toggleNav();
78+
}, 200);
79+
}
7880

7981
scrollToCurrentMenuItem();
8082
})();
@@ -314,6 +316,10 @@ function generateId(element) {
314316
return txt.replace(/\s/g,"").replace(/[^\w]/g,"_");
315317
}
316318

319+
function isMobile() {
320+
return window.innerWidth < 1000;
321+
}
322+
317323
function scrollToElement($element) {
318324
if ($element.length) {
319325
var topMargin = parseInt($element.css('margin-top')) || 20;
@@ -387,7 +393,7 @@ function setNavToggleListener() {
387393

388394
function toggleNav(hide) {
389395
// Don't run in mobile
390-
if (window.innerWidth < 1000) {
396+
if (isMobile()) {
391397
return;
392398
}
393399

@@ -430,6 +436,8 @@ function toggleNav(hide) {
430436
headerHidden = shouldHide;
431437
animating = true;
432438

439+
var $searchResultsContainer = $('.search-results-container');
440+
433441
if (shouldHide) {
434442
$('.nav-toggle').show();
435443
$everything.animate({
@@ -444,10 +452,21 @@ function toggleNav(hide) {
444452
animating = false;
445453
}
446454
});
455+
$searchResultsContainer.animate({
456+
"height": parseFloat($searchResultsContainer.css('height')) + headerHeight
457+
}, {
458+
duration: 250,
459+
complete: function() {
460+
$searchResultsContainer.css('height', '');
461+
$everything.addClass('header-is-hidden');
462+
}
463+
});
447464
} else {
448465
$('.nav-toggle').hide();
449466
$everything.css('height', parseFloat($everything.css('height')) + headerHeight);
450467
$everything.css('margin-top', 0-headerHeight);
468+
$searchResultsContainer.css('height', parseFloat($searchResultsContainer.css('height')) + headerHeight);
469+
$searchResultsContainer.css('margin-top', headerHeight);
451470
$nav.show();
452471
$everything.animate({
453472
"margin-top": '0',
@@ -456,6 +475,9 @@ function toggleNav(hide) {
456475
duration: 250,
457476
complete: function() {
458477
animating = false;
478+
$searchResultsContainer.css('height', '');
479+
$searchResultsContainer.css('margin-top', 0);
480+
$everything.removeClass('header-is-hidden');
459481
}
460482
});
461483
}

static/search.less

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
}
5454
}
5555

56+
// Desktop styles for search
57+
@media screen and (min-width: @breakpoint) {
58+
#everything:not(.header-is-hidden) #left > .bottom .search-results-container {
59+
height: calc(~"100vh - @{brand-height} - @{breadcrumb-height}");
60+
top: @brand-height + @breadcrumb-height;
61+
}
62+
}
63+
5664
#left > .bottom {
5765
//Search Results
5866
.search-results-container{
@@ -64,13 +72,8 @@
6472
background: #fff;
6573
left: 0;
6674
overflow-y: auto;
67-
transition: -webkit-backdrop-filter backdrop-filter background @transition-speed ease;
68-
69-
// Desktop styles
70-
@media screen and (min-width: @breakpoint) {
71-
height: calc(~"100vh - @{brand-height} - @{breadcrumb-height}");
72-
top: @brand-height + @breadcrumb-height;
73-
}
75+
transition: all @transition-speed ease;
76+
transition-property: -webkit-backdrop-filter, backdrop-filter, background;
7477

7578
.search-cancel{
7679
color: @code-color;

0 commit comments

Comments
 (0)