-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
113 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<div id="smoothScrollableContainer" ref="smoothScrollableContainer"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted, Ref, ref } from 'vue'; | ||
const body = document.body; | ||
const smoothScrollableContainer = ref() as Ref<HTMLDivElement>; | ||
let sy = 0; | ||
let dy = sy; | ||
const DAMPING = 0.1; | ||
function render() { | ||
//We calculate our container position by linear interpolation method | ||
dy = li(dy, sy, DAMPING); | ||
dy = ~~(dy * 100) / 100; | ||
smoothScrollableContainer.value.style.transform = `translate3d(${0}px, -${dy}px, 0px)`; | ||
window.requestAnimationFrame(render); | ||
} | ||
function li(a: number, b: number, n: number) { | ||
return (1 - n) * a + n * b; | ||
} | ||
function easeScroll() { | ||
sy = window.pageYOffset; | ||
} | ||
onMounted(() => { | ||
// TODO: this is stupid, it makes the body of the entire page be the total length of the list | ||
// TODO: so it lets you transform all the way down, replace this with something smarter | ||
// TODO: so we dont have to hide the scrollbar from the body | ||
body.style.height = smoothScrollableContainer.value.clientHeight + 'px'; | ||
// Bind a scroll function | ||
window.addEventListener('scroll', easeScroll); | ||
window.requestAnimationFrame(render); | ||
}) | ||
</script> | ||
|
||
<style scoped lang="postcss"> | ||
::-webkit-scrollbar { | ||
width: 0 !important; | ||
} | ||
#smoothScrollableContainer { | ||
@apply fixed z-20; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters