Coder Social home page Coder Social logo

reach-somewhere's Introduction

Reach Somewhere

Easily monitor content (scroll) to reach a certain position, in vue react framework.

โœจ Features

  • Listen for the roll arrival position
  • Support for multiple listening
  • vue react hook and directive available

๐Ÿ‘จโ€๐Ÿ’ป Usage

Install

pnpm add reach-somewhere

Use of Vue

Directive

import { createApp } from 'vue'
import { ReachSwDirective } from 'reach-somewhere/vue'
const app = createApp(App)

// install ReachSwDirective
app.use(
  ReachSwDirective,
  {
    name: 'reach-sw', // customize directive name, default 'reach-sw'
  }
)

app.mount('#app')
<template>
  <div v-reach-sw="reachSwParams">
    ...
  </div>
</template>

<script setup lang="ts">
  const reachTop = {
    position: 'top 0px',
    debounceMs: 100,
    onReach: () => {},
    onLeave: () => {},
  }
  const reachBottom = {
    position: 'bottom 0px',
    debounceMs: 100,
    onReach: () => {},
  }
  const reachSwParams = [
    reachTop,
    reachBottom,
  ]
</script>

Hook

<template>
  <div ref="elRef">
    ...
  </div>
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  import { useReachSw } from 'reach-somewhere/vue'

  const elRef = ref<HTMLElement>()
  const reachSwParams = {
    position: 'bottom 0px',
    debounceMs: 100,
    onReach: () => {},
  }
  const reachSw = useReachSw(elRef, reachSwParams, { auto: true })
  // reachSw.listen()
  // reachSw.rmListen()
</script>

Use of React

Hook

import { useRef } from 'react'
import { useReachSw } from 'reach-somewhere/react'

function MyComponent() {
  const elRef = useRef(null)
  const reachSwParams = {
    position: 'bottom 0px',
    debounceMs: 100,
    onReach: () => {},
  }
  const reachSw = useReachSw(elRef, reachSwParams, { auto: true })
  // reachSw.listen()
  // reachSw.rmListen()

  return <div ref={elRef}>...</div>
}

License

Licensed under the MIT License.

reach-somewhere's People

Contributors

eddieyg avatar

Stargazers

 avatar

Watchers

 avatar

reach-somewhere's Issues

Possible supported

features

  • Reach the start-to-end range
  const reachSwParams = {
    direction: 'top',  // or 'bottom'
    start: '10px',
    end: '60px'
    debounceMs: 100,
    onReach: () => {},
    onLeave: () => {},
  }
  • Reaches a target
 const target = document.querySelector('#box')
  const reachSwParams = {
    direction: 'top',  // or 'bottom'
    target,  // or '#box'
    debounceMs: 100,
    onReach: () => {},
    onLeave: () => {},
  }

docs

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.