Skip to content

Commit

Permalink
fix: revert scoll but workaround and use document.body.scrollTop
Browse files Browse the repository at this point in the history
  • Loading branch information
kilianc committed May 22, 2024
1 parent 5c0eaa6 commit 61cc846
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ function main() {
return
}

// layout
// setup the layout
configureFileSelect()
addIncrementalButton()
addThemeButton()

// setup the content
configureCodeBlocks()
configureSyntaxHighlight('pre .code .editor')
addCoverageSpans('pre .coverage .editor')
Expand Down Expand Up @@ -113,22 +114,28 @@ function configureFileSelect() {
}

document.location.hash = e.target.value
document.querySelectorAll('.file').forEach((el) => (el.style.display = 'none'))
el.style.display = 'block'

let scrollUp = (times) => {
if (window.scrollY === 0 && times > 3) return
window.scrollTo(0, 0)
window.requestAnimationFrame(() => scrollUp(times + 1))
}
document.body.scrollTop = 0;

scrollUp(1)
document.querySelectorAll('.file').forEach((el) => (el.style.display = 'none'))
el.style.display = 'block'
})

files.value = selected
files.dispatchEvent(new Event('change'))
}

setInterval(() => {
console.log({ scrollY: window.scrollY, scrollTop: document.body.scrollTop })
let files = document.getElementById('files')
let selected = files[Math.floor(Math.random() * files.length)].value

if (files.value !== selected) {
files.value = selected
files.dispatchEvent(new Event('change'))
}
}, 200)

function addThemeButton() {
let isDark = localStorage.getItem('dark') === 'true'

Expand Down

0 comments on commit 61cc846

Please sign in to comment.