npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jood/appearer

v0.2.0

Published

javascript intersection observer

Downloads

31

Readme

@jood/appearer

javascript intersection observer


TRAVIS Codecov branch NPM version NPM license NPM download NPM bundle size

Quick link

Quick sample

Edit prod-dream-vc2ce

AppearStage

한 개의 뷰포트

Actors

  • BaseActor: 기본형. 화면에 진입, 이탈 이벤트를 전달 받을 수 있다.
  • OnceActor: 1번만. 화면에 진입할 때 한번만 appear 이벤트가 트리거 된다.(트리거 후 자동 관찰해제)
  • LazyActor: 1번만. OnceActor 와 동일하나 진입 후 이탈이 지정된 시간 보다 짧으면 진입으로 취급하지 않는다.

example

import { AppearStage, AppearEvent, BaseActor } from "@jood/appearer";

const someStage = new AppearStage();
someStage.init();

const baseActor = new BaseActor(document.querySelector(".my-some-box1"));
someStage.observe(baseActor);

const subscription = baseActor.events.subscribe((evt: AppearEvent) => {
  if (evt.type === AppearEvent.APPEAR) {
    // image.src = 'real-src';
    // showAnimationStart();
    // fetchMore();
    // ...
  } else if (evt.type === AppearEvent.DISAPPEAR) {
    // hideAnimationStart();
    // ...
  }
});

import { AppearStage, OnceActor } from "@jood/appearer";

const someStage = new AppearStage();
someStage.init();

const onceActor = new OnceActor(document.querySelector(".my-some-box1"));
someStage.observe(onceActor);

const subscription = onceActor.events.subscribe((evt: AppearEvent) => {
  image.src = "real-src";
  subscription.unsubscribe();
  onceActor.dispose();
});

import { AppearStage, AppearEvent, LazyActor } from "@jood/appearer";

const someStage = new AppearStage();
someStage.init();

const myList = new OnceActor(document.querySelectorAll(".my-some-box"));
myList.forEach((elBox) => {
  const lazyActor = new LazyActor(elBox);
  someStage.observe(lazyActor);

  const subscription = lazyActor.events.subscribe((evt: AppearEvent) => {
    const { element } = evt.actor;
    element.classList.add("is-active");
    subscription.unsubscribe();
    lazyActor.dispose();
  });
});

import { AppearStage, AppearEvent, LazyActor } from "@jood/appearer";

const elHorizontalContainer = document.querySelector(".my-horizonta-container");
const someStage = new AppearStage();

/**
 * Intersection observer options
 * @see https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
 **/
someStage.init({
  root: elHorizontalContainer,
  rootMargin: "0 25% 0 25%",
});

const myBoxList = elHorizontalContainer.querySelectorAll(".my-some-box");
myBoxList.forEach((elBox) => {
  const lazyActor = new LazyActor(elBox);
  someStage.observe(lazyActor);

  const subscription = lazyActor.events.subscribe((evt: AppearEvent) => {
    const { element } = evt.actor;
    element.classList.add("is-active");
    subscription.unsubscribe();
    lazyActor.dispose();
  });
});

import { AppearStage, AppearEvent, LazyActor } from '@jood/appearer';

let isLoading = false;

const someStage = new AppearStage();
someStage.init({
  rootMargin: '0 0 50% 0',
});

const myInfiniteLoading = new BaseAppear(document.querySelector('.my-list-foot-loading'));
someStage.observe(myInfiniteLoading);

const subscription = myInfiniteLoading.events.subscribe((evt: AppearEvent) => {
  if (evt.type === AppearEvent.APPEAR) {
    fetchMore();
  }
});

function fetchMore() {
  if (isLoading === true) return;
  isLoading = true;
  fetch(...).then((result) => {
    isLoading = false;
  });
}

This library was generated with Angular CLI