Skip to content

Commit 186a53f

Browse files
chrisvfritzAkryum
authored andcommitted
feat: hover class for item views (#90)
1 parent 9ae0210 commit 186a53f

File tree

7 files changed

+42
-27
lines changed

7 files changed

+42
-27
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,14 @@ export default {
135135
- ⚠️ You need to set the size of the virtual-scroller element and the items elements (for example, with CSS). Unless you are using [variable height mode](#variable-height-mode), all items should have the same height to prevent display glitches.
136136
- It is not recommended to use functional components inside RecycleScroller since the components are reused (so it will actually be slower).
137137
- The components used in the list should expect `item` prop change without being re-created (use computed props or watchers to properly react to props changes!).
138-
- You don't need to set `key` on list content (but you should on all nested `<img>`elements to prevent load glitches).
138+
- You don't need to set `key` on list content (but you should on all nested `<img>` elements to prevent load glitches).
139139
- The browsers have a height limitation on DOM elements, it means that currently the virtual scroller can't display more than ~500k items depending on the browser.
140+
- Since DOM elements are reused for items, it's recommended to define hover styles using the provided `hover` class instead of the `:hover` state selector (e.g. `.vue-recycle-scroller__item-view.hover` or `.hover .some-element-inside-the-item-view`).
140141

141142
### How does it work?
142143

143144
- The RecycleScroller creates pools of views to render visible items to the user.
144-
- A view is holding a rendered item, and is reused inside its pool.
145+
- A view is holding a rendered item, and is reused inside its pool.
145146
- For each type of item, a new pool is created so that the same components (and DOM trees) are reused for the same type.
146147
- Views can be deactivated if they go off-screen, and can be reused anytime for a newly visible item.
147148

@@ -195,7 +196,7 @@ When the user scrolls inside RecycleScroller, the views are mostly just moved ar
195196

196197
- `item`: item being rendered in a view.
197198
- `index`: reflects each item's position in the `items` array
198-
- `active`: is the view active. An active view is considered visible and being positionned by `RecycleScroller`. An inactive view is not considered visible and hidden from the user. Any rendering-related computations should be skipped if the view is inactive.
199+
- `active`: is the view active. An active view is considered visible and being positioned by `RecycleScroller`. An inactive view is not considered visible and hidden from the user. Any rendering-related computations should be skipped if the view is inactive.
199200

200201
### Other Slots
201202

dist/vue-virtual-scroller.esm.js

Lines changed: 16 additions & 6 deletions
Large diffs are not rendered by default.

dist/vue-virtual-scroller.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-virtual-scroller.umd.js

Lines changed: 16 additions & 6 deletions
Large diffs are not rendered by default.

docs-src/src/App.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,13 @@ body {
7676
box-sizing: border-box;
7777
}
7878
79-
.vue-recycle-scroller__item,
8079
.vue-recycle-scroller__item-view {
8180
cursor: pointer;
8281
user-select: none;
8382
-moz-user-select: none;
8483
-webkit-user-select: none;
8584
}
8685
87-
.vue-recycle-scroller__item {
88-
height: 50px;
89-
}
90-
9186
.tr, .td {
9287
box-sizing: border-box;
9388
}
@@ -101,8 +96,7 @@ body {
10196
display: block;
10297
}
10398
104-
.vue-recycle-scroller__item:hover,
105-
.vue-recycle-scroller__item-view:hover {
99+
.vue-recycle-scroller__item-view.hover {
106100
background: #4fc08d;
107101
color: white;
108102
}

docs-src/src/components/RecycleScrollerDemo.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ export default {
232232
padding: 12px;
233233
}
234234
235-
.vue-recycle-scroller__item .letter .td {
236-
height: 200px;
237-
}
238-
239235
.letter.big {
240236
font-weight: normal;
241237
height: 200px;

src/components/RecycleScroller.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
:key="view.nr.id"
2323
:style="ready ? { transform: 'translateY(' + view.top + 'px)' } : null"
2424
class="vue-recycle-scroller__item-view"
25+
:class="{ hover: hoverKey === view.nr.key }"
26+
@mouseenter="hoverKey = view.nr.key"
27+
@mouseleave="hoverKey = null"
2528
>
2629
<slot
2730
:item="view.item"
@@ -57,6 +60,7 @@ export default {
5760
pool: [],
5861
totalHeight: 0,
5962
ready: false,
63+
hoverKey: null,
6064
}
6165
},
6266

0 commit comments

Comments
 (0)