Vue ScrollTop 컴포넌트
ScrollTop은 일정 스크롤 위치를 지나면 나타나서 페이지 맨 위로 빠르게 이동하게 해 주는 컴포넌트예요. 긴 페이지에서 위로 올라가는 수고를 덜어 줘요.
출처: 문서
본문
Vue ScrollTop Component
ScrollTop gets displayed after a certain scroll position and used to navigates to the top of the page quickly.
Import
import ScrollTop from 'primevue/scrolltop';
Accessibility
Screen Reader ScrollTop은 로케일 API의 aria.scrollTop 프로퍼티를 기본으로 참조하는 aria-label이 붙은 button 요소를 사용해요. 모든 유효한 속성은 button 요소로 그대로 전달되므로 여러분만의 aria role과 속성을 사용할 수도 있어요. Keyboard Support Key Function enter 맨 위로 스크롤해요. space 맨 위로 스크롤해요.
Basic
ScrollTop은 기본적으로 window 스크롤을 감시해요.
<ScrollTop />
Element
target 프로퍼티를 parent로 설정하면 ScrollTop이 스크롤 콘텐츠를 갖는 부모 요소에 묶여요.
<ScrollPanel style="width: 250px; height: 200px">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vitae et leo duis ut diam. Ultricies mi quis hendrerit dolor magna eget est lorem. Amet consectetur adipiscing
elit ut. Nam libero justo laoreet sit amet. Pharetra massa massa ultricies mi quis hendrerit dolor magna. Est ultricies integer quis auctor elit sed vulputate. Consequat ac felis donec et. Tellus orci ac auctor augue mauris. Semper
feugiat nibh sed pulvinar proin gravida hendrerit lectus a. Tincidunt arcu non sodales neque sodales. Metus aliquam eleifend mi in nulla posuere sollicitudin aliquam ultrices. Sodales ut etiam sit amet nisl purus. Cursus sit amet
dictum sit amet. Tristique senectus et netus et malesuada fames ac turpis egestas. Et tortor consequat id porta nibh venenatis cras sed. Diam maecenas ultricies mi eget mauris. Eget egestas purus viverra accumsan in nisl nisi.
Suscipit adipiscing bibendum est ultricies integer. Mattis aliquam faucibus purus in massa tempor nec.
</p>
<ScrollTop target="parent" :threshold="100" icon="pi pi-arrow-up" :buttonProps="{ severity: 'contrast', raised: true, rounded: true }" />
</ScrollPanel>
Composition API Example
<template>
<div class="card flex justify-center">
<ScrollPanel style="width: 250px; height: 200px">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vitae et leo duis ut diam. Ultricies mi quis hendrerit dolor magna eget est lorem. Amet consectetur adipiscing
elit ut. Nam libero justo laoreet sit amet. Pharetra massa massa ultricies mi quis hendrerit dolor magna. Est ultricies integer quis auctor elit sed vulputate. Consequat ac felis donec et. Tellus orci ac auctor augue mauris. Semper
feugiat nibh sed pulvinar proin gravida hendrerit lectus a. Tincidunt arcu non sodales neque sodales. Metus aliquam eleifend mi in nulla posuere sollicitudin aliquam ultrices. Sodales ut etiam sit amet nisl purus. Cursus sit amet
dictum sit amet. Tristique senectus et netus et malesuada fames ac turpis egestas. Et tortor consequat id porta nibh venenatis cras sed. Diam maecenas ultricies mi eget mauris. Eget egestas purus viverra accumsan in nisl nisi.
Suscipit adipiscing bibendum est ultricies integer. Mattis aliquam faucibus purus in massa tempor nec.
</p>
<ScrollTop target="parent" :threshold="100" icon="pi pi-arrow-up" :buttonProps="{ severity: 'contrast', raised: true, rounded: true }" />
</ScrollPanel>
</div>
</template>
Scroll Top
Props
| Name | Type | Default | Description |
|---|---|---|---|
| target | HintedString<"window" | "parent"> | window | Target of the ScrollTop. |
| threshold | number | 400 | Defines the threshold value of the vertical scroll position of the target to toggle the visibility. |
| icon | string | - | Icon to display. |
| behavior | string | smooth | Defines the scrolling behaviour, 'smooth' adds an animation and 'auto' scrolls with a jump. |
| buttonProps | object | - | Used to pass all properties of the ButtonProps to the Button component. |
| dt | any | - | It generates scoped CSS variables using design tokens for the component. |
| pt | PassThrough | - | Used to pass attributes to DOM elements inside the component. |
| ptOptions | any | - | Used to configure passthrough(pt) options of the component. |
| unstyled | boolean | false | When enabled, it removes component related styles in the core. |
Pass Through Options
| Name | Type | Description |
|---|---|---|
| root | any | Used to pass attributes to the root's DOM element. |
| hooks | any | Used to manage all lifecycle hooks. |
| transition | ScrollTopPassThroughTransitionType | Used to control Vue Transition API. |
Theming
CSS Classes
| Class | Description |
|---|---|
| p-scrolltop | Class name of the root element |
| p-scrolltop-icon | Class name of the icon element |