fix sidenotes
This commit is contained in:
parent
819775f0a7
commit
dbcc82a10a
@ -10,23 +10,41 @@
|
||||
export let title, date;
|
||||
|
||||
// deal with sidenote collisions
|
||||
onMount(async () => {
|
||||
function tileNotes() {
|
||||
const minNoteGap = 15;
|
||||
let sidenotes = Array.from(document.getElementsByClassName('sidenote'));
|
||||
// let sidenotes = Array.from(document.getElementsByClassName('sidenote'));
|
||||
let notes = document.querySelectorAll('.sidenote');
|
||||
if (window.getComputedStyle(notes[0]).position === 'fixed') {
|
||||
// fixed position means we are in mobile territory, so
|
||||
// get rid of the overflow stuff and then exit
|
||||
for (let note of notes) {
|
||||
note.style.top = '';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let labels = document.querySelectorAll('label.counter');
|
||||
var prev = 0;
|
||||
for (var i=0; i < sidenotes.length; i++) {
|
||||
let note = sidenotes[i];
|
||||
let {y, height} = note.getBoundingClientRect();
|
||||
y += window.scrollY; // getBoundingClientRect is relative to viewport
|
||||
if (y < prev + minNoteGap) {
|
||||
note.style.top = `${prev + minNoteGap}px`;
|
||||
prev = prev + minNoteGap + height;
|
||||
for (var i=0; i < notes.length; i++) {
|
||||
let labelTop = labels[i].getBoundingClientRect().y + window.scrollY;
|
||||
let noteHeight = notes[i].getBoundingClientRect().height;
|
||||
if (labelTop < prev + minNoteGap) {
|
||||
// there is a collision
|
||||
notes[i].style.top = `${prev + minNoteGap}px`;
|
||||
prev = prev + minNoteGap + noteHeight;
|
||||
}
|
||||
else {
|
||||
prev = y + height;
|
||||
// no collision
|
||||
notes[i].style.top = `${labelTop}px`;
|
||||
prev = labelTop + noteHeight;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
tileNotes();
|
||||
window.addEventListener('resize', tileNotes);
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
@ -40,6 +40,7 @@
|
||||
position: absolute;
|
||||
left: calc(50vw + var(--content-width) / 2 + 1rem);
|
||||
max-width: 12rem;
|
||||
hyphens: auto;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ html {
|
||||
font-size: 20px;
|
||||
line-height: 1.3;
|
||||
letter-spacing: -0.005em;
|
||||
color: #1e1e1e;
|
||||
}
|
||||
|
||||
body {
|
||||
|
@ -16,6 +16,9 @@ const config = {
|
||||
kit: {
|
||||
// hydrate the <div id="svelte"> element in src/app.html
|
||||
adapter: staticAdapter(),
|
||||
prerender: {
|
||||
default: true,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user