All Projects → ryanve → Verge

ryanve / Verge

Licence: mit
Get viewport dimensions, detect elements in the viewport

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Verge

React Awesome Reveal
React components to add reveal animations using the Intersection Observer API and CSS Animations.
Stars: ✭ 346 (-49.64%)
Mutual labels:  viewport
Vue Mq
📱 💻 Define your breakpoints and build responsive design semantically and declaratively in a mobile-first way with Vue.
Stars: ✭ 474 (-31%)
Mutual labels:  viewport
Viewport Checker
Little utility to detect if elements are currently within the viewport 🔧
Stars: ✭ 596 (-13.25%)
Mutual labels:  viewport
React Native Responsive Grid
Bringing the Web's Responsive Design to React Native
Stars: ✭ 369 (-46.29%)
Mutual labels:  responsive-design
Argon Dashboard
Argon - Dashboard for Bootstrap 4 by Creative Tim
Stars: ✭ 429 (-37.55%)
Mutual labels:  responsive-design
In View
Get notified when a DOM element enters or exits the viewport. 👀
Stars: ✭ 4,684 (+581.8%)
Mutual labels:  viewport
Breakpoint Slicer
Slice media queries with ease
Stars: ✭ 332 (-51.67%)
Mutual labels:  responsive-design
Responsive Html Email Template
Responsive HTML email template designed to work on all major email platforms and smartphones
Stars: ✭ 662 (-3.64%)
Mutual labels:  responsive-design
Reverie
🎨 A ridiculously elegant Jekyll theme.
Stars: ✭ 442 (-35.66%)
Mutual labels:  responsive-design
Light Bootstrap Dashboard React
React version of Light Bootstrap Dashboard
Stars: ✭ 561 (-18.34%)
Mutual labels:  responsive-design
React Socks
🎉 React library to render components only on specific viewports 🔥
Stars: ✭ 400 (-41.78%)
Mutual labels:  viewport
Eqio
A simple, tiny alternative to element/container queries
Stars: ✭ 427 (-37.85%)
Mutual labels:  responsive-design
Pixi Viewport
A highly configurable viewport/2D camera designed to work with pixi.js
Stars: ✭ 532 (-22.56%)
Mutual labels:  viewport
React On Screen
Check if a react component in the viewport
Stars: ✭ 357 (-48.03%)
Mutual labels:  viewport
Isinviewport
An ultra-light jQuery plugin that tells you if an element is in the viewport but with a twist.
Stars: ✭ 646 (-5.97%)
Mutual labels:  viewport
Animate
A tiny JS (5KB) library to trigger animations on elements when they are within the viewport 👓
Stars: ✭ 340 (-50.51%)
Mutual labels:  viewport
Motus
Animation library that mimics CSS keyframes when scrolling.
Stars: ✭ 502 (-26.93%)
Mutual labels:  viewport
Kick Off
UIkit 3 Starter Layout / Templates - Quick start for your UIkit 3 project!
Stars: ✭ 672 (-2.18%)
Mutual labels:  responsive-design
Material Kit
Free and Open Source UI Kit for Bootstrap 4, React, Vue.js, React Native and Sketch based on Google's Material Design
Stars: ✭ 5,672 (+725.62%)
Mutual labels:  responsive-design
Textblock
Continuously responsive typesetting — Demo:
Stars: ✭ 536 (-21.98%)
Mutual labels:  responsive-design

verge

verge is a compact set of cross-browser viewport utilities written in native JavaScript. It includes the ability to detect if an element is in the current viewport. It works as a standalone module, an ender module, or as a jQuery plugin. (npm: verge)

API

Accuracy

  • Requires <!DOCTYPE html>
  • verge's viewport methods represent the CSS viewport: the @media (width) and @media (height) breakpoints.
  • At certain zooms the viewport dimensions given by verge may be 1px off the expected @media value due to native rounding. For greater precision (at a slight speed tradeoff) consider actual.

.viewportW()

verge.viewportW() // -> viewport width in pixels

.viewportH()

verge.viewportH() // -> viewport height in pixels

.viewport()

Get both CSS viewport dimensions as an object with width and height properties.

verge.viewportW() === verge.viewport().width  // always true
verge.viewportH() === verge.viewport().height // always true

The .viewportW() syntax is slightly faster.

.inViewport()

Test if any part of an element (or the first element in a matched set) is in the current viewport. Returns boolean.

verge.inViewport(elem) // true if elem is in the current viewport
verge.inViewport(elem, 100) // true if elem is in the current viewport or within 100px of it
verge.inViewport(elem, -100) // true if elem is in the current viewport and not within 99px of the edge

Performance tip for sites that only scroll along 1 axis

verge.inViewport(elem) === verge.inX(elem) && verge.inY(elem) // always true
Substitute inViewport with: inY on vertical sites, inX on horizontal ones.
  • On pages without horizontal scroll, inX is always true.
  • On pages without vertical scroll, inY is always true.
  • If the viewport width is >= the document width, then inX is always true.

.inX()

Test if any part of an element (or the first element in a matched set) is in the same x-axis section as the viewport. Returns boolean.

verge.inX(elem) // true if elem is in same x-axis as the viewport (exact)
verge.inX(elem, 100) // true if elem is in same x-axis as the viewport or within 100px of it
verge.inX(elem, -100) // true if elem in is the viewport and not within 99px of the edge

.inY()

Test if any part of an element (or the first element in a matched set) is in the same y-axis section as the viewport. Returns boolean.

verge.inY(elem) // true if elem is in same y-axis as the viewport (exact)
verge.inY(elem, 100) // true if elem is in same y-axis as the viewport or within 100px of it
verge.inY(elem, -100) // true if elem in is the viewport and not within 99px of the edge

.scrollX()

Get the horizontal scroll position in pixels. (Like window.scrollX, but cross-browser.)

verge.scrollX() // -> horizontal pixels scrolled

.scrollY()

Get the vertical scroll position in pixels. (Like window.scrollY, but cross-browser.)

verge.scrollY() // -> vertical pixels scrolled

.mq()

.mq(mediaQueryString)

Test if a media query is active.

verge.mq('(min-color:2)') // -> boolean
verge.mq('tv') // -> boolean

.rectangle()

.rectangle(element, cushion?)

Get an a object containing the properties top, bottom, left, right, width, and height with respect to the top-left corner of the current viewport, and with an optional cushion amount. Its return is like that of the native getBoundingClientRect.

The optional cushion parameter is an amount of pixels to act as a cushion around the element. If none is provided then it defaults to 0 and the rectangle will match the native rectangle. If a cushion is specified, the properties are adjusted according to the cushion amount. If the cushion is positive the rectangle will represent an area that is larger that the actual element. If the cushion is negative then the rectangle will represent an area that is smaller that the actual element.

verge.rectangle(element) // rectangle object
verge.rectangle(element, 100) // rectangle object adjusted by 100 pixels

.aspect()

.aspect(object?)

Get the aspect ratio of the viewport or of an object with width/height properties.

verge.aspect() // -> viewport aspect ratio
verge.aspect(element) // -> element aspect ratio
verge.aspect(screen) // -> device aspect ratio
1 < verge.aspect() // => landscape orientation

Integrate

jQuery

jQuery.extend(verge)

ender

ender build verge

Contribute

Contribute by making edits in ./src or reporting issues.

npm install
npm test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].