Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid autoscroll when changing tab in tabbed example. #226

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/js/06-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,23 +283,6 @@ document.addEventListener('DOMContentLoaded', function () {
el.classList.add(tabActive)
})
})

var toolbarOffset = 0
var toolbar = document.querySelector('.toolbar')
if (toolbar.offsetHeight) {
toolbarOffset = toolbar.offsetHeight
}
var offset = document.querySelector('.navbar').offsetHeight + toolbarOffset + 20

var bodyRect = document.body.getBoundingClientRect().top
var elementRect = tab.getBoundingClientRect().top
var elementPosition = elementRect - bodyRect
var offsetPosition = elementPosition - offset

window.scrollTo({
top: offsetPosition,
behavior: 'smooth',
})
}

// Tabbed code
Expand Down
17 changes: 0 additions & 17 deletions src/js/08-tabs-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,6 @@ document.addEventListener('DOMContentLoaded', function () {
})
})

var toolbarOffset = 0
var toolbar = document.querySelector('.toolbar')
if (toolbar.offsetHeight) {
toolbarOffset = toolbar.offsetHeight
}
var offset = document.querySelector('.navbar').offsetHeight + toolbarOffset + 20

var bodyRect = document.body.getBoundingClientRect().top
var elementRect = tab.getBoundingClientRect().top
var elementPosition = elementRect - bodyRect
var offsetPosition = elementPosition - offset

window.scrollTo({
top: offsetPosition,
behavior: 'smooth',
})

if (sessionStorageAvailable) {
window.sessionStorage.setItem('code_example_language', lang)
}
Expand Down