Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

License

NotificationsYou must be signed in to change notification settings

vtimofeev/vue-check-view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple plugin that checks element position on the screen (viewport) and adds classes to element:

  1. In viewport classes:view-in and one of [view-in--gt-half,view-in--gt-thrid,view-in--full],
  2. Out viewport classes:view-out and one of [view-out--below,view-out--above]

It listensscroll andresize window events and supports modern browsers (Firefox, Chrome, Edge).Supports vue.js version 2 and higher.

Install

npm i vue vue-check-view --save
import checkView from 'vue-check-view'Vue.use(checkView)

or (only for test)

<script src="http://vtimofeev.github.io/vue-check-view/plugin.js">

Add directive 'view' to elements

Example 1, simple

Auto add classes to element

<div v-view>    Content</div>

Example 2, advanced with use handler

Auto add classes to element and executeHandler

<div v-view="viewHandler">    Content</div>
funtion viewHandler (e) {    console.log(e.type) // 'enter', 'exit', 'progress'    console.log(e.percentInView) // 0..1 how much element overlap the viewport    console.log(e.percentTop) // 0..1 position of element at viewport 0 - above , 1 - below    console.log(e.percentCenter) // 0..1 position the center of element at viewport 0 - center at viewport top, 1 - center at viewport bottom    console.log(e.scrollPercent) // 0..1 current scroll position of page    console.log(e.scrollValue) // 0..1 last scroll value (change of page scroll offset)    console.log(e.target.rect) // element.getBoundingClientRect() result}

Example 3, once time the handler will be executed when element appears on screen

<div v-view.once="onceHandler">    Content</div>
funtion onceHandler (e) {    console.log(e.type) // 'enter', 'exit', 'progress'    console.log(e.percentInView) // 0..1 how much element overlap the viewport    console.log(e.percentTop) // 0..1 position of element at viewport 0 - above , 1 - below    console.log(e.percentCenter) // 0..1 position the center of element at viewport 0 - center at viewport top, 1 - center at viewport bottom    console.log(e.scrollPercent) // 0..1 current scroll position of page    console.log(e.scrollValue) // 0..1 last scroll value (change of page scroll offset)    console.log(e.target.rect) // element.getBoundingClientRect() result}

DEMO

Browser

https://vtimofeev.github.io/vue-check-view/index.html

Live image

demo

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp