Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Detect the visibility of elements in the page

NotificationsYou must be signed in to change notification settings

Happy-Coding-Clans/vue-lazy-container

Repository files navigation

npm

English |中文

Introduction

vue lazy container,By detect the visibility of elements in the page, decide whether to load resources and render.

Why

When the page content exceeds one screen, we often want to load and render only the data of the current screen,As the page scrolls, load and render the following. This can greatly improve the speed of page opening,And reduce additional network requests(xhr)。vue-lazy-container can just help us solve this problem.

Online Demo

More detail please refer to thisdemo.

Install

npm install vue-lazy-container

or

yarn add vue-lazy-container

Usage

Write the following in mian.js:

importVueLazyContainerfrom"vue-lazy-container";Vue.use(VueLazyContainer);

Example:

<template><vue-lazy-containertag-name="div"id=1 @change="visibilityChange"><templatev-if="isLoaded">      <!-- your content --></template></vue-lazy-container></template><script>exportdefault{data(){return{isLoaded:false};},methods:{// visibility changevisibilityChange(entry,observer,id){const{ isIntersecting}=entry;// visibilityif(isIntersecting){this.isLoaded=true;// you can send ajax request or other logic}}}};</script>

API

Props

PropDescriptionTypeOptional valueDefault
tagNameElement TagNameElement.tagNamediv、span、p、img、i、a etc.-
idcontainer idString, Number--
intersectionOptionIntersection Observer OptionObjectroot、rootMargin、threshold-

Event

Event NameDescriptionCallback Parameters
changeElement visible change eventsIntersectionObserverEntry、observer、id

License

http://www.opensource.org/licenses/mit-license.php

About

Detect the visibility of elements in the page

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    [8]ページ先頭

    ©2009-2025 Movatter.jp