GithubHelp home page GithubHelp logo

peshrawahmed / nuxt-render-on-scroll Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dell-mic/nuxt-render-on-scroll

0.0 1.0 0.0 2.15 MB

A Vue/Nuxt component that allows you to lazily render components only when they are scrolled into the viewport.

License: MIT License

JavaScript 62.89% Vue 37.11%

nuxt-render-on-scroll's Introduction

nuxt-render-on-scroll

nuxt-render-on-scroll - A Vue/Nuxt component that allows you to lazily render components only when they are scrolled into the viewport.

Based on the idea from vue-render-on-scroll and adopted for SSR usage in Nuxt.js: Adding v-if="false" to the content of the component as long as the component is not in the current viewport or while in SSR mode.

Nevertheless, it should still be usable independent of Nuxt with stock Vue.

Install

yarn add nuxt-render-on-scroll
# OR
npm i nuxt-render-on-scroll
import RenderOnScroll from 'nuxt-render-on-scroll'
export default {
  components: {
    RenderOnScroll,
    // ...
  },
}

Simple Usage

<render-on-scroll>
  <div>This content will be renderd only when it enters viewport</div>
</render-on-scroll>

Advanced Usage

<render-on-scroll :offset-y="100">
  <div>This content will already be rendered when scrolled 100px near it</div>
</render-on-scroll>
<render-on-scroll height="180px" :offset-y="-40">
  <div>
    This content will only be rendered when at least 40px scrolled into the
    180px high placeholder space
  </div>
</render-on-scroll>

Placeholder Support

A placeholder can also be shown before the scroll reaches the element. This will be usefull if you want to show something else while the component is rendering or if you are fetching asynchronous data from.

<render-on-scroll>
  <template #placeholder>
    <div>
      This content will be rendered before scroll reaches the main element. 
    </div>
  </template>
  <div>This content will be renderd only when it enters viewport</div>
</render-on-scroll>

Configuration Options

prop type default comments
height String '' CSS string for height property of the wrapping div. Useful to preserve the space while to content is not rendered yet. Can be used in combination with a negative value offsetY render only when scrolled into the content area, e.g., for large charts.
offsetY Number 0 Additional amount of pixel to be added on the content's bounds. E.g. value of 100 will render the content when scrolled within 100px near it.

Development

This project is based on vue-sfc-rollup

Clone this repo

git clone [email protected]:Michi-4G/nuxt-render-on-scroll.git
cd nuxt-render-on-scroll

Install dependencies

npm install

Run development server

npm run serve

Build for production

npm run build

nuxt-render-on-scroll's People

Contributors

dell-mic avatar dependabot[bot] avatar peshrawahmed avatar

Watchers

 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.