Skip to content

Commit

Permalink
Use vue-observe-visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Dec 23, 2016
1 parent 686f027 commit 219457b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Smooth scroll with any amount of data ([demo](https://akryum.github.io/vue-virtu
```
npm install --save vue-virtual-scroller
```

**⚠️ `vue-virtual-scroller` now uses [vue-observe-visibility](https://github.com/Akryum/vue-observe-visibility) to automatically refresh itself when shown to prevent display glitches. This means you need to include the polyfills needed by `vue-observe-visibility` for this to work.**

## Default import

Install all the components:
Expand Down
4 changes: 4 additions & 0 deletions dist/vue-virtual-scroller.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
display: block;
overflow: hidden;
}

.test h1[data-v-5ee0142a] {
color: #40b883;
}
2 changes: 1 addition & 1 deletion dist/vue-virtual-scroller.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/build.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/build.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-virtual-scroller",
"description": "Smooth scrolling for any amount of data",
"version": "0.3.0",
"version": "0.4.0",
"author": {
"name": "Guillaume Chau",
"email": "guillaume.b.chau@gmail.com"
Expand Down Expand Up @@ -51,6 +51,7 @@
"webpack-merge": "^1.1.2"
},
"dependencies": {
"vue-observe-visibility": "^0.1.1",
"vue-resize": "^0.1.0"
}
}
13 changes: 12 additions & 1 deletion src/components/VirtualScroller.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<component :is="mainTag" class="virtual-scroller" @scroll="updateVisibleItems">
<component :is="mainTag" class="virtual-scroller" @scroll="updateVisibleItems" v-observe-visibility="handleVisibilityChange">
<component :is="containerTag" class="item-container" :style="itemContainerStyle">
<component :is="contentTag" class="items" :style="itemsStyle">
<template v-if="renderers">
Expand All @@ -16,6 +16,7 @@

<script>
import { ResizeObserver } from 'vue-resize'
import { ObserveVisibility } from 'vue-observe-visibility'
export default {
name: 'virtual-scroller',
Expand All @@ -24,6 +25,10 @@ export default {
ResizeObserver,
},
directives: {
ObserveVisibility,
},
props: {
items: {
type: Array,
Expand Down Expand Up @@ -101,6 +106,12 @@ export default {
scrollToItem (index) {
this.$el.scrollTop = index * this.itemHeight
},
handleVisibilityChange (isVisible) {
if (isVisible) {
this.updateVisibleItems()
}
},
},
mounted () {
Expand Down

0 comments on commit 219457b

Please sign in to comment.