Skip to content

Commit

Permalink
center clicked tab to a third of viewport height
Browse files Browse the repository at this point in the history
  • Loading branch information
stefano-ottolenghi committed Jul 23, 2024
1 parent 6fdbe90 commit 9088a24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/js/06-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ document.addEventListener('DOMContentLoaded', function () {
}
var offset = document.querySelector('.navbar').offsetHeight + toolbarOffset + 20

var vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
var bodyRect = document.body.getBoundingClientRect().top
var elementRect = tab.getBoundingClientRect().top
var elementPosition = elementRect - bodyRect
var offsetPosition = elementPosition - offset
var offsetPosition = elementPosition - offset - vh/3

Check failure on line 298 in src/js/06-code.js

View workflow job for this annotation

GitHub Actions / build

Operator '/' must be spaced

window.scrollTo({
top: offsetPosition,
behavior: 'smooth',
top: offsetPosition, // scroll so that element is within a third of viewport height

Check failure on line 301 in src/js/06-code.js

View workflow job for this annotation

GitHub Actions / build

Multiple spaces found before '// scroll so t...'
})
}

Expand Down
6 changes: 3 additions & 3 deletions src/js/08-tabs-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ document.addEventListener('DOMContentLoaded', function () {
}
var offset = document.querySelector('.navbar').offsetHeight + toolbarOffset + 20

var vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
var bodyRect = document.body.getBoundingClientRect().top
var elementRect = tab.getBoundingClientRect().top
var elementPosition = elementRect - bodyRect
var offsetPosition = elementPosition - offset
var offsetPosition = elementPosition - offset - vh/3

Check failure on line 77 in src/js/08-tabs-block.js

View workflow job for this annotation

GitHub Actions / build

Operator '/' must be spaced

window.scrollTo({
top: offsetPosition,
behavior: 'smooth',
top: offsetPosition, // scroll so that element is within a third of viewport height

Check failure on line 80 in src/js/08-tabs-block.js

View workflow job for this annotation

GitHub Actions / build

Multiple spaces found before '// scroll so t...'
})

if (sessionStorageAvailable) {
Expand Down

0 comments on commit 9088a24

Please sign in to comment.