Skip to content

Commit 10b9c0a

Browse files
githajaeclaude
andcommitted
Fix mobile scrollytelling: rootMargin + lower threshold
On mobile the sticky diagram panel covers the top 40vh, so IntersectionObserver (with viewport as root) kept steps "intersecting" even when they were visually hidden behind the panel. Fix: on screens ≤900px use rootMargin '-40% 0px 0px 0px' to exclude the sticky-panel band from the observation area, and lower the threshold from 0.5 → 0.3 so diagram updates fire earlier (more responsive feel). Observer is also rebuilt on resize/orientation change. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4f2d061 commit 10b9c0a

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

_layouts/research-interests.html

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,35 @@ <h2 class="s-title">The AI<br>Database System.</h2>
247247
if (activeStep >= 5) alignConnector();
248248
}
249249

250-
var observer = new IntersectionObserver(function (entries) {
251-
entries.forEach(function (entry) {
252-
if (entry.isIntersecting) {
253-
update(parseInt(entry.target.dataset.step, 10));
254-
}
250+
/* On mobile the sticky diagram panel occupies the top 40vh, so we tell
251+
the observer to ignore that band and only watch the bottom 60vh.
252+
A lower threshold (0.3) also makes updates feel more immediate. */
253+
var mq = window.matchMedia('(max-width: 900px)');
254+
255+
function makeObserver() {
256+
var mobile = mq.matches;
257+
return new IntersectionObserver(function (entries) {
258+
entries.forEach(function (entry) {
259+
if (entry.isIntersecting) {
260+
update(parseInt(entry.target.dataset.step, 10));
261+
}
262+
});
263+
}, {
264+
threshold: mobile ? 0.3 : 0.5,
265+
rootMargin: mobile ? '-40% 0px 0px 0px' : '0px'
255266
});
256-
}, { threshold: 0.5 });
267+
}
257268

269+
var observer = makeObserver();
258270
steps.forEach(function (s) { observer.observe(s); });
259271
update(1); // initialise diagram to step 1
260272

261-
/* Re-align on resize (e.g. font scaling, window resize) */
273+
/* Rebuild observer and re-align connector on resize / orientation change */
262274
window.addEventListener('resize', function () {
263275
if (currentStep >= 5) alignConnector();
276+
observer.disconnect();
277+
observer = makeObserver();
278+
steps.forEach(function (s) { observer.observe(s); });
264279
});
265280
}());
266281
</script>

0 commit comments

Comments
 (0)