Skip to content

Commit 50b71aa

Browse files
committed
Fix flickering of generated toc at fixed position when scrolling page vertically
1 parent e6a617a commit 50b71aa

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/AnalysisPage/GraphicalClustering/graphicalClusteringPage.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function ReportControls({ tissue, toggleReport, currentView }) {
156156
function LandscapeGraphicalClustering({ tissue, setTissue }) {
157157
return (
158158
<div className="graphical-clustering-summary-container row mb-2">
159-
<div className="lead col-12">
159+
<div className="lead col-12 page-summary">
160160
Explore multi-omic changes and associated pathway enrichment results
161161
over the training time course per tissue in adult rats. Compare
162162
responses between male and female rats, identify pathways affected in
@@ -186,7 +186,7 @@ function LandscapeGraphicalClustering({ tissue, setTissue }) {
186186
function MitoChondriaGraphicalAnalysis({ tissue, setTissue }) {
187187
return (
188188
<div className="graphical-clustering-summary-container row mb-2">
189-
<div className="lead col-12">
189+
<div className="lead col-12 page-summary">
190190
Explore the mitochondria-selected (using{' '}
191191
<ExternalLink
192192
to="https://www.broadinstitute.org/mitocarta/mitocarta30-inventory-mammalian-mitochondrial-proteins-and-pathways"

src/AnalysisPage/GraphicalClustering/sharedLib.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export const tocbotConfig = {
66
ignoreSelector: '.toc-ignore',
77
headingsOffset: 100,
88
scrollSmoothOffset: -100,
9-
tocScrollOffset: 100,
109
};
1110

1211
export const pass1b06GraphicalClusteringLandscapeImageLocation =
@@ -17,15 +16,32 @@ export const pass1b06GraphicalClusteringMitoImageLocation =
1716

1817
// fix toc position to the top of the page when scrolling
1918
export function handleScroll() {
19+
// page elements to compute total offset height
20+
// to fix toc to the top of the page when scrolling
21+
const pageHeader = document.querySelector('.page-header');
22+
const summary = document.querySelector('.page-summary');
23+
const intro = document.getElementById('introduction');
24+
const control = document.querySelector('.controlPanelContainer');
25+
// current scroll height of the page
26+
const scrollHeight =
27+
window.scrollY ||
28+
document.body.scrollTop ||
29+
(document.documentElement && document.documentElement.scrollTop);
30+
// conditions required to fix toc to the top of the page
31+
const page = document.querySelector('.graphicalClusteringPage');
2032
const toc = document.getElementById('TOC');
21-
if (toc) {
22-
const tocBottom = toc.offsetTop + toc.offsetHeight;
2333

24-
if (window.scrollY >= tocBottom) {
25-
toc.classList.add('toc-fix-top');
26-
}
34+
if (page && toc) {
35+
const offsetHeight =
36+
pageHeader.offsetHeight +
37+
summary.offsetHeight +
38+
intro.offsetHeight +
39+
control.offsetHeight +
40+
30;
2741

28-
if (window.scrollY <= tocBottom) {
42+
if (scrollHeight >= offsetHeight) {
43+
toc.classList.add('toc-fix-top');
44+
} else {
2945
toc.classList.remove('toc-fix-top');
3046
}
3147
}

src/sass/_analysisPage.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
border-radius: 5px;
174174
padding: 0.5rem;
175175
overflow-x: auto;
176-
transition: top 0.3s ease;
176+
transition: top 0.5s ease;
177177

178178
&.toc-fix-top {
179179
position: fixed;

0 commit comments

Comments
 (0)