GitHub - isaact/vue-infinity: Vue Infinity is a lightweight library for creating resource efficient apps. Unload parts of your UI when not visible and build easy to layout virtual scrollers that can present unlimited content while keeping resource usage fixed. (original) (raw)

Decorative clouds

Vue-Infinity

Build lightning-fast Vue apps that only render what is on-screen

Vue-Infinity brings a radical efficiency boost to your UI by applying the same principle that powers 3D engines: if it’s not in visible, it doesn’t get rendered. This lets your app handle hundreds or thousands of elements without bloating memory, janking or killing batteries.

Whether you’re building infinite feeds, carousels, media galleries, or dashboardsβ€”Vue-Infinity keeps your app fast, smooth, and efficient.

Table of Contents

The gallery-ce is a web component built on top of the Carousel component that provides an easy way to display a gallery of images with features like lazy loading, responsive layout, and dynamic sizing. It's designed to efficiently handle large collections of images while maintaining smooth performance.

Usage Examples

Plain JavaScript

React

import { useEffect, useRef } from 'react'; import { registerElements } from 'vue-infinity';

registerElements();

function Gallery() { const galleryRef = useRef(null);

useEffect(() => { if (galleryRef.current) { galleryRef.current.updateImages([ 'image1.jpg', 'image2.jpg', 'image3.jpg' ]); } }, []);

return ; }

Svelte

Vue

Props

Prop Type Default Description
items String (JSON) '[]' Array of image URLs or objects with url, title, and alt properties
height String '400px' Height of the gallery container
width String '100%' Width of the gallery container
num-cols-to-show Number 1 Number of columns to show (can be fractional for partial items)
num-rows-to-show Number 1 Number of rows to show
gap String '1rem' Gap between items
vertical-scroll Boolean false Whether to scroll vertically instead of horizontally

Methods

Method Parameters Description
updateImages newItems (Array or JSON string) Update the gallery with new images
scrollToItem itemIndex (Number) Scroll to a specific item by index

Note: The registerElements() function must be called once before using any vue-infinity web components.

The Carousel component works like the Gallery but for any type of content. It provides a flexible way to display any kind of content in a carousel layout with lazy loading and responsive design.

{{ item.title }}

{{ item.description }}

πŸͺ‚ InfiniteCarousel

The InfiniteCarousel works like the Carousel but with the ability to fetch more data as the user scrolls. It integrates with the useInfiniteList composable to handle data fetching and caching.

Creating an InfiniteList

import { useInfiniteList } from 'vue-infinity';

const infiniteList = useInfiniteList({ fetchItems: async (page, signal) => { const response = await fetch(/api/items?page=${page}, { signal }); return response.json(); }, itemsPerPage: 50, maxPagesToCache: 5 });

Using with InfiniteList

πŸ‘» Ghost Component

The Ghost component is useful when you want to apply visibility based rendering to anything. It optimizes performance by conditionally rendering its slot content. When off-screen, the content is replaced by a dimensionally-identical placeholder.

Component Usage

This content will be replaced when not visible.

Directive Usage

πŸ”Ž AutoObserver

The AutoObserver combines a MutationObserver and IntersectionObserver to allow you to track a container's child elements. It automatically handles new elements and cleaning up removed ones.

const containerRef = ref();

const { disconnect } = useAutoObserver( containerRef, (entries) => { entries.forEach(entry => { console.log('Element visibility changed:', entry.isIntersecting); }); }, { rootMargin: '200px', threshold: 0.1, filter: el => el.classList.contains('observe-me') } );

πŸ“¦ Installation

πŸ§ͺ Live Demo

Explore the live demo here: https://tewolde.co/vueInfinity/

πŸ§‘β€πŸ’» Run Playground App

To run the playground application locally:

Releases

v0.8.4 (2025-11-26)

Enhancements

InfiniteCarousel Component:

Playground App:

v0.8.0 (2025-08-11)

New Components and Features

Gallery Web Component:

v0.7.0 (2024-07-01)

πŸ“„ License

Apache 2.0 License - https://opensource.org/licenses/Apache-2.0