Giter Site home page Giter Site logo

catalystio / vue-waypoint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scaccogatto/vue-waypoint

0.0 0.0 0.0 2.85 MB

trigger functions and events based on the element position on the screen

License: MIT License

JavaScript 15.96% HTML 5.18% Vue 40.40% TypeScript 38.46%

vue-waypoint's Introduction

VueWaypoint

trigger functions and events based on the element position on the screen

Latest Release

Demo

Simple demo page

Open your browser console and see what's going on while scrolling up and down

Features

  • Vue 3
  • No dependencies
  • Flexible
  • Typescript
  • Battle tested
  • Customizable
  • Solid project (3+ years)
  • Supports slots

Getting started

npm

npm i vue-waypoint

Vue component

<template>
  <Waypoint @change="onChange">
    <!-- anything you want here -->
  </Waypoint>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import { Waypoint } from 'vue-waypoint'

export default defineComponent({
  name: "SomeComponent",
  components: {
    Waypoint
  },
  setup() {
    const onChange = (waypointState) => {
      // Going can be:
      // IN
      // OUT
      console.log(waypointState.going);

      // Direction can be:
      // UP
      // DOWN
      // LEFT
      // RIGHT
      console.log(waypointState.direction);
    }

    return { onChange };
  }
});
</script>

Props

active

  • Can use a reactive variable
  • Can set true/false dinamically

Usage:

  • Enable the waypoint: <Waypoint :active="true" />
  • Disable the waypoint: <Waypoint :active="false" />

options

Usage:

Options example:

const options: IntersectionObserverInit = {
  root: document,
  rootMargin: '0px 0px 0px 0px',
  threshold: [0.25, 0.75]
};

tag

  • Set your preferred tag for the element

  • Defaults to div

  • Waypoint as div: <Waypoint :tag="'div'" /> --> renders --> <div class="waypoint"></div>

  • Waypoint as span: <Waypoint :tag="'span'" /> --> renders --> <span class="waypoint"></span>

  • Waypoint as p: <Waypoint :tag="'p'" /> --> renders --> <p class="waypoint"></p>

disableCssHelpers

  • Disable automatic CSS classes on the Waypoint component
  • Defaults to false

Usage:

  • Enable helpers (default): <Waypoint :disableCssHelpers="false" />
  • Disable helpers: <Waypoint :disableCssHelpers="true" />

DOM result:

  • With CSS helpers: <Waypoint /> --> renders --> <div class="waypoint going-in direction-down"></div>
  • Without CSS helpers: <Waypoint :disableCssHelpers="true" /> --> renders --> <div></div>

CSS helpers

  • Zero configuration needed
  • Useful for simple CSS animations

The component comes with three classes:

  • waypoint: set when the waypoint is ready
  • going-in, going-out: dinamically changed when the waypoint comes in and out
  • direction-up, direction-down, direction-left, direction-right: dinamically changed when the direction changes

Examples:

  • <Waypoint class="waypoint going-in direction-up" /> - the element is visible and came from bottom and is going top (natural scroll)
  • <Waypoint class="waypoint going-in direction-down" /> - the element is visible and came from top and is going up (reverse natural scroll)
  • <Waypoint class="waypoint going-out direction-up" /> - the element is not visible and came from bottom and is going top
  • <Waypoint class="waypoint going-out direction-down" /> - the element is not visible and came from top and is going up

Events

change

Emitted every time the waypoint detects a change.

<template>
  <Waypoint @change="onChange" />
</template>
const changeFunction = (waypointState) => {..}
WaypointState {
  el: Element,
  going: 'IN' | 'OUT';
  direction: 'UP' | 'DOWN' | 'LEFT' | 'RIGHT';
};

Development

  1. Fork the repository
  2. Run the project (npm i && npm run serve)
  3. Follow Conventional Commits spec for your commits
  4. Open a pull request

LEGACY: Vue2 and Nuxt version

vue-waypoint for Vue2 repository

vue-waypoint's People

Contributors

scaccogatto avatar dependabot[bot] avatar iamike avatar iamandrewluca avatar morr avatar colloquet avatar blackgearit avatar jpt avatar hephaest avatar bralat avatar rasikas avatar sa16ot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.