Skip to content

Commit 1259ce4

Browse files
Avoid autoscroll when changing tab in tabbed example. (#226)
I think it's a bad UX if the page moves unexpectedly. When looking at examples, people may want to look at them together with the text leading to it, and they have to manually scroll back up to.
1 parent 0e6b4c6 commit 1259ce4

File tree

2 files changed

+0
-34
lines changed

2 files changed

+0
-34
lines changed

src/js/06-code.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,23 +283,6 @@ document.addEventListener('DOMContentLoaded', function () {
283283
el.classList.add(tabActive)
284284
})
285285
})
286-
287-
var toolbarOffset = 0
288-
var toolbar = document.querySelector('.toolbar')
289-
if (toolbar.offsetHeight) {
290-
toolbarOffset = toolbar.offsetHeight
291-
}
292-
var offset = document.querySelector('.navbar').offsetHeight + toolbarOffset + 20
293-
294-
var bodyRect = document.body.getBoundingClientRect().top
295-
var elementRect = tab.getBoundingClientRect().top
296-
var elementPosition = elementRect - bodyRect
297-
var offsetPosition = elementPosition - offset
298-
299-
window.scrollTo({
300-
top: offsetPosition,
301-
behavior: 'smooth',
302-
})
303286
}
304287

305288
// Tabbed code

src/js/08-tabs-block.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ document.addEventListener('DOMContentLoaded', function () {
6363
})
6464
})
6565

66-
var toolbarOffset = 0
67-
var toolbar = document.querySelector('.toolbar')
68-
if (toolbar.offsetHeight) {
69-
toolbarOffset = toolbar.offsetHeight
70-
}
71-
var offset = document.querySelector('.navbar').offsetHeight + toolbarOffset + 20
72-
73-
var bodyRect = document.body.getBoundingClientRect().top
74-
var elementRect = tab.getBoundingClientRect().top
75-
var elementPosition = elementRect - bodyRect
76-
var offsetPosition = elementPosition - offset
77-
78-
window.scrollTo({
79-
top: offsetPosition,
80-
behavior: 'smooth',
81-
})
82-
8366
if (sessionStorageAvailable) {
8467
window.sessionStorage.setItem('code_example_language', lang)
8568
}

0 commit comments

Comments
 (0)