Skip to content

Instantly share code, notes, and snippets.

@eightHundreds
Last active August 3, 2020 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eightHundreds/9b7c166676a45754f6f1d0c24801e3fc to your computer and use it in GitHub Desktop.
Save eightHundreds/9b7c166676a45754f6f1d0c24801e3fc to your computer and use it in GitHub Desktop.
滚动条隐藏
<template>
</template>
<script lang="ts">
const onSomethingScrollFactory = () => {
const SCROLL_HIDE_TIMEOUT = 150;
const removeScrolling = debounce((el) => {
el.classList.remove('scrolling');
}, SCROLL_HIDE_TIMEOUT);
return throttle((e: Event) => {
const el = e.target as HTMLDivElement;
if (el?.classList?.contains('scrolling') === false) {
el.classList.add('scrolling');
removeScrolling(el);
} else {
removeScrolling(el);
}
}, 50);
};
@Component()
export default class App extends Vue {
onAuthorized (ssoid: string) {
// eslint-disable-next-line
window.addEventListener('scroll', this.onSomethingScroll, true);
}
destroyed() {
// eslint-disable-next-line
window.removeEventListener('scroll', this.onSomethingScroll!);
}
}
</script>
<style lang="scss">
.app-wrap {
height: 100%;
overflow-y: overlay; // 等效auto,但是不占空间
}
::-webkit-scrollbar {/* 滚动条整体样式 */
width: 4px; /* 高宽分别对应横竖滚动条的尺寸 */
height: 0;
}
::-webkit-scrollbar-thumb {/* 滚动条里面小方块 */
border-radius: 2px;
background: rgba(0, 0, 0, 0);
height: 60px;
}
.scrolling::-webkit-scrollbar-thumb{
background: rgba(0, 0, 0, 0.13);
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment