All Projects → developit → Preact Scroll Viewport

developit / Preact Scroll Viewport

Licence: mit
Preact Component that renders homogeneous children only when visible

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Preact Scroll Viewport

robinjs-website
Alexa like assistant in 40 lines of code
Stars: ✭ 31 (-73.73%)
Mutual labels:  preact, virtual
Val
VirtualDOM abstraction layer - give yourself better integration and full control over the DOM with any virtual DOM library that uses a Hyperscript-like API such as React and Preact.
Stars: ✭ 181 (+53.39%)
Mutual labels:  virtual, preact
React Fit To Viewport
Stars: ✭ 92 (-22.03%)
Mutual labels:  viewport
React Virtualized Sticky Tree
A React component for efficiently rendering tree like structures with support for position: sticky
Stars: ✭ 115 (-2.54%)
Mutual labels:  virtual
Virtual Office
Virtual Office gives you transparency on what Zoom.us rooms are currently occupied and who is present
Stars: ✭ 103 (-12.71%)
Mutual labels:  virtual
Jetpack
🚀 Jetpack – Webpack made more convenient.
Stars: ✭ 1,326 (+1023.73%)
Mutual labels:  preact
Kissui.scrollanim
CSS3 scroll animation library
Stars: ✭ 1,442 (+1122.03%)
Mutual labels:  viewport
Offline Gallery
🎈 A 16kb Preact & Redux based Progressive Web App that offers an offline gallery experience of external images.
Stars: ✭ 90 (-23.73%)
Mutual labels:  preact
Next Todos
200 lines realtime todos app powered by next.js, preact, jet, redux and now
Stars: ✭ 117 (-0.85%)
Mutual labels:  preact
Leo
Highly Extensible, Declarative Static Site Generator
Stars: ✭ 100 (-15.25%)
Mutual labels:  preact
Virtualseccons
An ongoing list of virtual cybersecurity conferences.
Stars: ✭ 113 (-4.24%)
Mutual labels:  virtual
React Virtuoso
The most powerful virtual list component for React
Stars: ✭ 1,347 (+1041.53%)
Mutual labels:  virtual
Dataformsjs
🌟 DataFormsJS 🌟 A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.
Stars: ✭ 95 (-19.49%)
Mutual labels:  preact
Aura Operating System
AuraOS, the Franco-English Operating System developed in C# using Cosmos!
Stars: ✭ 111 (-5.93%)
Mutual labels:  virtual
Nanocomponent Adapters
🔌 - Convert a nanocomponent to a component for your favourite API or library (web components, (p)react, angular)
Stars: ✭ 94 (-20.34%)
Mutual labels:  preact
Isonscreen
Simple jQuery plugin to determine if an element is within the viewport
Stars: ✭ 115 (-2.54%)
Mutual labels:  viewport
Colors App
🎨 A PWA for copying values from popular color palettes. Supports HEX, RGB, and HSL formats.
Stars: ✭ 90 (-23.73%)
Mutual labels:  preact
Pimg
📷 Mini Image Lazy Loader for P(R)eact and Vue
Stars: ✭ 97 (-17.8%)
Mutual labels:  preact
Tiny Atom
Pragmatic and concise state management.
Stars: ✭ 109 (-7.63%)
Mutual labels:  preact
Mobx Preact
MobX bindings for Preact
Stars: ✭ 117 (-0.85%)
Mutual labels:  preact

<ScrollViewport /> for Preact

NPM Travis

A compositional component that renders its children based on the current viewport.

Useful for those super important business applications where one must show all million rows.

JSFiddle Demo

preview

Usage Example

Simply wrap a large collection of children in this component, and they will be rendered based on the viewport. You can define a default row height (defaultRowHeight) to use prior to dimensions being available, or a static row height (rowHeight) to avoid style recalculation entirely. If rowHeight is not provided, the height of the first row will be calculated and extrapolated.

// create 100,000 children:
let children = [];
for (let i=1; i<100000; i++) {
	children.push(<div class="row">{i}</div>);
}

// ...but only render what is in-viewport:
render(
	<ScrollViewport rowHeight={22}>
		{children}
	</ScrollViewport>
);

Props

Prop Type Description
rowHeight Number Static height of a row (prevents style recalc)
defaultRowHeight Number Initial height of a row prior to dimensions being available
overscan Number Number of extra rows to render above and below visible list. Defaults to 10. *
sync Boolean If true, forces synchronous rendering **

* Why overscan? Rendering normalized blocks of rows reduces the number of DOM interactions by grouping all row renders into a single atomic update.

** About synchronous rendering: It's best to try without sync enabled first. If the normal async rendering behavior is fine, leave sync turned off. If you see flickering, enabling sync will ensure every update gets out to the screen without dropping renders, but does so at the expense of actual framerate.

Without Overscan With Overscan

Simple Example

View this example on JSFiddle

import ScrollViewport from 'preact-scroll-viewport';

class Demo extends Component {
    // 30px tall rows
    rowHeight = 30;

    render() {
		// Generate 100,000 rows of data
		let rows = [];
		for (let x=1e5; x--; ) rows[x] = `Item #${x+1}`;

        return (
            <ScrollViewport class="list" rowHeight={this.rowHeight}>
				{ rows.map( row => (
					<div class="row">{row}</div>
				)) }
			</ScrollViewport>
        );
    }
}

render(Demo, document.body);

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].