question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Fire events in v-virtual-scroll

See original GitHub issue

Problem to solve

According to the docs, v-virtual-scroll doesn’t fire any events, but it would be nice if it would fire one if it (almost) reaches the end of its items stream. You could hook this into a fetching function that retrieves more items and easily implement ‘infinite scrolling’ this way.

Proposed solution

When v-virtual-scroll reaches the end of its items stream, fire an event that designates this (for instance $emit('end-of-stream')). One could even make it configurable at how many items before the end of the stream the event should be fired?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
dschreijcommented, Aug 22, 2020

Alright @KaelWD, your suggestion lead me into the right direction. I indeed had to listen to the native scroll event of v-virtual-scroll, e.g.

<v-virtual-scroll
  :items="items"
  @scroll.native="scrolling"
>

Then the script to fire an event at the end of the stream is as follows:

import {debounce} from 'lodash'
export default {
    created () {
        this.scrolling = debounce(this.scrolling, 200)
    },
    scrolling (event) {
        const element = event.currentTarget || event.target
        if (element && element.scrollHeight - element.scrollTop === element.clientHeight) {
           this.$emit('scroll-end')
        }
    }
}

which did the trick. One could add a margin to the end area, so that items can already be fetched before the end of the current stream is reached, e.g.:

const margin = 50 // Get from somewhere else e.g. a prop
if (element && element.scrollHeight - element.scrollTop === element.clientHeight - margin) {

All in all, this was indeed relatively easy to achieve, but I still think this would be a worthwhile addition to the library 😄

0reactions
trizotticommented, Nov 8, 2021

Hey guys, how do you scroll to an specific item on the list programatically?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Virtual scrolling: Core principles and basic implementation in ...
Learn how to implement virtual scrolling in React. ... The scroller will request the data via this method, ... Scroll event handling.
Read more >
Infinite Virtual Scroll with the Angular CDK - Fireship
The component emits a custom event whenever the scrolled index changes. This allows you to run code when a specific item is scrolled...
Read more >
Grid with remote virtual scrolling fires mutiple read requests ...
Hi, When using the Grid with remote datasource and virtual scrolling, the grid often fires 2 or more of the same read request,...
Read more >
Angular 7 Virtual Scroll - To Infinity and Beyond - YouTube
Learn how to use the new Virtual Scroll behavior in Angular CDK v7 to build a list that is infinite, animated, and realtime...
Read more >
Build your own virtual scroll - Part II
Scroll events can fire very rapidly as the user scrolls, ... an animation and requests that the browser shall call a specified function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found