All Projects → monoeq → monolazy

monoeq / monolazy

Licence: MIT license
Extended nanocomponent providing onEnter callback

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to monolazy

nanoconstruct
Tiny tool to test and develop nanocomponents
Stars: ✭ 12 (-42.86%)
Mutual labels:  nanocomponent
LazyHTML
LazyHTML is an OpenSource Javascript Library that Supports Lazy Loading of any elements without Modifying Code, LazyHTML can lazy load Ads, Videos, Images, Widgets, Javascript, CSS, Inline-Javascript, Inline-CSS & Any HTML.
Stars: ✭ 47 (+123.81%)
Mutual labels:  intersection-observer
component-box
A little component cacher 📦
Stars: ✭ 25 (+19.05%)
Mutual labels:  nanocomponent
React Intersection Observer
React implementation of the Intersection Observer API to tell you when an element enters or leaves the viewport.
Stars: ✭ 2,689 (+12704.76%)
Mutual labels:  intersection-observer
intersection-observer-debugger
A script you include during development that shows the root, target, and intersection every time an IntersectionObserver is triggered.
Stars: ✭ 61 (+190.48%)
Mutual labels:  intersection-observer
react-intersection-observer-api-example
Showcasing of the Intersection Observer API in React with createRef()
Stars: ✭ 13 (-38.1%)
Mutual labels:  intersection-observer
bs-react-is-visible
A small library that lets you know whether a component is visible on screen or not.
Stars: ✭ 15 (-28.57%)
Mutual labels:  intersection-observer
svelte-intersection-observer
Detect if an element is in the viewport using the Intersection Observer API
Stars: ✭ 151 (+619.05%)
Mutual labels:  intersection-observer
react-infinite-scroll-list
Manage infinite list with the IntersectionObserver API
Stars: ✭ 20 (-4.76%)
Mutual labels:  intersection-observer
react-awesome-reveal
React components to add reveal animations using the Intersection Observer API and CSS Animations.
Stars: ✭ 564 (+2585.71%)
Mutual labels:  intersection-observer
intersection-observer-netflix
clase #2 de youtube.com/LeonidasEsteban
Stars: ✭ 20 (-4.76%)
Mutual labels:  intersection-observer
impression
👀Element view notifier
Stars: ✭ 77 (+266.67%)
Mutual labels:  intersection-observer
react-use-observer
Performant react hooks for WebApi Observers, useResizeObserver, useInteractionObserver, useMutationObserver
Stars: ✭ 19 (-9.52%)
Mutual labels:  intersection-observer
react-spring-pop
Animate React elements when they enter the viewport with physics based animations
Stars: ✭ 17 (-19.05%)
Mutual labels:  intersection-observer
vue-in-viewport-mixin
Vue 2 mixin to determine when a DOM element is visible in the client window
Stars: ✭ 99 (+371.43%)
Mutual labels:  intersection-observer
svelte-inview
A Svelte action that monitors an element enters or leaves the viewport.🔥
Stars: ✭ 358 (+1604.76%)
Mutual labels:  intersection-observer
react-intersection-observer-hook
React hook to use IntersectionObserver declaratively
Stars: ✭ 58 (+176.19%)
Mutual labels:  intersection-observer
vue-observable
IntersectionObserver, MutationObserver and PerformanceObserver in Vue.js
Stars: ✭ 24 (+14.29%)
Mutual labels:  intersection-observer

monolazy


Extended nanocomponent which provides a single onEnter callback using on-intersect when component enters the viewport.

Usage

Extend monolazy the same way you extend nanocomponent

var html = require('nanohtml')
var MonoLazy = require('monolazy')

class TestComponent extends MonoLazy {
  // implement onEnter, fires when element enters viewport
  onEnter () {
    this.rerender()
  }

  // use the hasEntered property to determine if element has entered viewport
  createElement () {
    return html`<div>${this.hasEntered ? 'here i am' : 'patiently waiting'}</div>`
  }
}

Details

monolazy itself only implements load and unload. It is up to you to implement onEnter and createElement and any another methods!

If you need to implement your own load/unload, make sure you call the parent's load/unload:

class TestComponent extends MonoLazy {
  load (element) {
    super.load(element)
    // custom load here
  }

  unload (element) {
    super.unload(element)
    // custom unload here
  }

  onEnter () {
    this.rerender()
  }

  createElement () {
    return html`<div>${this.hasEntered ? 'here i am' : 'patiently waiting'}</div>`
  }
}

Polyfill

If you need to support browsers without Intersection Observer, you can use a polyfill:

require('intersection-observer')
var MonoLazy = require('monolazy')

See Also

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].