vue-scroll-detect
Vue Scroll Detect
Detect component visibility change on scrolling.
Installation
yarn add vue-scroll-detect
Example
See examples/
at Code Sandbox
Usage
ES Import
import { Scrollable, ScrollContainer } from 'vue-scroll-detect'
UMD build
<script src="vue-scroll-detect.umd.min.js"></script>
<script>
const { ScrollContainer, Scrollable } = VueScrollDetect
...
</script>
visible
and invisible
events are emitted when element visibility changes in a scrollable container, either an element or window
.
To watch for element visibility, put it inside Scrollable
, which in turns must be nested inside a ScrollContainer
. See src/examples
for more.
Example
<ScrollContainer :initial-event="true">
<ul>
<li
v-for="(item, index) in items"
ref="items"
:key="item.key"
>
<Scrollable
@visible="onVisible(item, index, $event)"
@invisible="onInvisible(item, index, $event)"
>
<span class="item">{{ item.value }}</span>
</Scrollable>
</li>
</ul>
</ScrollContainer>
Props
ScrollContainer
Name | Type | Description |
---|---|---|
root |
Boolean | To watch visibility of elements as they enter/exit the window viewport. By default this is false , so the container itself must be scrollable eg: overflow: scroll . |
initial-event |
Boolean | Whether to receive initial visibility of Scrollable elements on component mount. |
enter-offset |
String | CSS length value (eg: "1em"). If the value is positive, emit visible event before element enters the container/viewport by the distance. Otherwise, emit afterwards. |
exit-offset |
String | CSS length value (eg: "1em"). If the value is positive, emit invisible event before element exits the container/viewport by the distance. Otherwise, emit afterwards. |
License
Vue Scroll Detect is released under the MIT License.
Dependencies
@babel/core: ^7.7.4@vue/cli-plugin-babel: ^4.0.0@vue/cli-plugin-eslint: ^4.0.0@vue/cli-plugin-unit-jest: ^4.0.5@vue/cli-service: ^4.0.0@vue/eslint-config-standard: ^4.0.0@vue/test-utils: ^1.0.0-beta.29babel-eslint: ^10.0.3core-js: ^3.3.2eslint: ^5.16.0eslint-plugin-vue: ^5.0.0rimraf: ^3.0.0rollup: ^1.27.8rollup-plugin-babel: ^4.3.3rollup-plugin-commonjs: ^10.1.0rollup-plugin-node-resolve: ^5.2.0rollup-plugin-terser: ^5.1.2rollup-plugin-vue: ^5.1.4vue: ^2.6.10vue-template-compiler: ^2.6.10