Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-valim committed Sep 18, 2023
1 parent 0cd24cb commit 238f179
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions assets/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,21 @@ function getLivebookImportUrl (livebookUrl, notebookUrl) {
}

// Check if the device width is below a certain threshold (e.g., 768px for mobile)
if (window.innerWidth <= 768) {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
document.addEventListener('click', function (e) {
if (window.innerWidth <= 768) {
const target = e.target.closest('a[href^="#"]')
if (target) {
e.preventDefault()

const targetId = this.getAttribute('href').substring(1)
const targetId = target.getAttribute('href').substring(1)
const targetElement = document.getElementById(targetId)

if (targetElement) {
const offset = 45 // Adjust this offset as needed
const targetPosition = targetElement.getBoundingClientRect().top + window.scrollY - offset

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

Large diffs are not rendered by default.

0 comments on commit 238f179

Please sign in to comment.