All Projects → xobotyi → Viewport.jquery

xobotyi / Viewport.jquery

Licence: mit
viewport.jquery - simple but handy jQuery plugin adding methods and CSS selectors to check if element is in certain viewport

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Viewport.jquery

Isonscreen
Simple jQuery plugin to determine if an element is within the viewport
Stars: ✭ 115 (-26.28%)
Mutual labels:  viewport, jquery-plugin, jquery
Stickystack.js
A jQuery plugin that creates a stacking effect by sticking panels as they reach the top of the viewport.
Stars: ✭ 287 (+83.97%)
Mutual labels:  viewport, jquery-plugin, jquery
Isinviewport
An ultra-light jQuery plugin that tells you if an element is in the viewport but with a twist.
Stars: ✭ 646 (+314.1%)
Mutual labels:  viewport, jquery-plugin, jquery
Jquery Connections
Add stylable lines connecting page elements. ⮑ Handy for visualizing relations and graph edges. ⮐
Stars: ✭ 151 (-3.21%)
Mutual labels:  jquery-plugin, jquery
Xzoom
jQuery Zoom Gallery plugin
Stars: ✭ 120 (-23.08%)
Mutual labels:  jquery-plugin, jquery
Fotorama
A simple, stunning, powerful jQuery gallery.
Stars: ✭ 1,567 (+904.49%)
Mutual labels:  jquery-plugin, jquery
Jquery Scrolllock
Locks mouse wheel scroll inside container, preventing it from propagating to parent element
Stars: ✭ 109 (-30.13%)
Mutual labels:  jquery-plugin, jquery
Slide And Swipe Menu
⚡️ A sliding swipe menu that works with touchSwipe library.
Stars: ✭ 135 (-13.46%)
Mutual labels:  jquery-plugin, jquery
Checkboxes.js
☑️ A jQuery plugin that gives you nice powers over your checkboxes.
Stars: ✭ 127 (-18.59%)
Mutual labels:  jquery-plugin, jquery
Normalmap.js
normalmap.js is a library for creating simple interactive lighting effects using normal maps.
Stars: ✭ 156 (+0%)
Mutual labels:  jquery-plugin, jquery
Jquery Menu Editor
Multilevel Menu Editor for Bootstrap 4.x (Html & Javascript code)
Stars: ✭ 144 (-7.69%)
Mutual labels:  jquery-plugin, jquery
Convform
A jQuery plugin that transforms a form into an interactive chat.
Stars: ✭ 141 (-9.62%)
Mutual labels:  jquery-plugin, jquery
Magnificent.js
🔍 Zoom responsively, images & more, w/ jQuery.
Stars: ✭ 153 (-1.92%)
Mutual labels:  jquery-plugin, jquery
Jquery Rwdimagemaps
Responsive Image Maps jQuery Plugin
Stars: ✭ 1,511 (+868.59%)
Mutual labels:  jquery-plugin, jquery
Jquery.resizeend
A custom event that fires when a user stops resizing their browser.
Stars: ✭ 155 (-0.64%)
Mutual labels:  jquery-plugin, jquery
Footer Reveal
A jQuery plugin for easy implementation of the 'fixed/reveal' footer effect. Demo here:
Stars: ✭ 111 (-28.85%)
Mutual labels:  jquery-plugin, jquery
Jquery.fbmessenger
Fake Facebook Messenger interactions on an iPhone with a simple jQuery plugin!
Stars: ✭ 130 (-16.67%)
Mutual labels:  jquery-plugin, jquery
Image Select
Image Select is an extension of Chosen, a jQuery plugin that makes long, unwieldy select boxes much more user-friendly. It provides image support for Single and Multi select HTML tags.
Stars: ✭ 145 (-7.05%)
Mutual labels:  jquery-plugin, jquery
Jquery Udraggable
make elements draggable by mouse or touch
Stars: ✭ 107 (-31.41%)
Mutual labels:  jquery-plugin, jquery
Pg Calendar
📆 beautiful and eidetic date picker
Stars: ✭ 109 (-30.13%)
Mutual labels:  jquery-plugin, jquery

viewport.jquery

NPM version NPM downloads License

About

viewport is simple but handy jQuery plugin adding methods and CSS selectors to check if element is in certain viewport. Furthermore - you will be able to check position relation of two separate elements even if the are not kins. Plugin uses getBoundingClientRect() to determine elements positions so be sure it meets your browser support the requirements. ] version 1.x.x uses different detection principe, which will work in almost any browser but works 10-30 times slower

Requirements

  • jQuery 3+ (written and tested with 3.3.1)

Installation

Download it from GitHub, or install via NPM:

npm i viewport.jquery

Include it in your JS code or link it in html page

[script src="viewport.jquery.js" type="text/javascript"][/script]

Now you able to

$(".myAwesomeElement:in-viewport").yaay();
// or
$(".myAwesomeElement").viewport().inViewport(); // true if in viewport

Usage

viewport.jquery provides you two different way of relation detection: CSS pseudo-selectors and jQuery methods

CSS pseudo-selectors

All following selectors can be used without parameters and bracket.

threshold parameter must be an integer, it extends (if it positive) or reduces (if it negative) viewport sizes, but only in calculations.

viewportSelector parameter must be a string, determines the selector of element that will be treated like a viewport, if more than one element corresponds given selector - the first one of them will be used. Otherwise viewport will be found in element's parents, it will be first element that has scroll or the BODY element of none.

General

:hasScroll
:hasScrollVertical
:hasScrollHorizontal

It will filter element if it has a scroll possibility, in meaning that element contents has bigger sizes than it's own.

:inViewport([ int threshold = 0 [, string viewportSelector ]])

It will filter the element if each it's border is within or equal viewport's borders.

Any side of element exceeds viewport's borders

:aboveTheViewport([ int threshold = 0 [, string viewportSelector ]])
:belowTheViewport([ int threshold = 0 [, string viewportSelector ]])
:leftOfViewport([ int threshold = 0 [, string viewportSelector ]])
:rightOfViewport([ int threshold = 0 [, string viewportSelector ]])

Any side of element is within viewport's borders

:aboveTheViewportPartly([ int threshold = 0 [, string viewportSelector ]])
:belowTheViewportPartly([ int threshold = 0 [, string viewportSelector ]])
:leftOfViewportPartly([ int threshold = 0 [, string viewportSelector ]])
:rightOfViewportPartly([ int threshold = 0 [, string viewportSelector ]])

Element exceeds viewport size and cant fit it

:exceedsViewport([ int threshold = 0 [, string viewportSelector ]])
:exceedsViewportVertical([ int threshold = 0 [, string viewportSelector ]])
:exceedsViewportHorizontal([ int threshold = 0 [, string viewportSelector ]])

jQuery methods

$('').viewport().hasScroll();

Return: boolean, representing if element has scroll;

$('').viewport().scrollableParent();

Return:
HTMLElement, representing first parent element that has scroll or BODY element oif none;

$('').viewport().relativePosition([ viewport = undefined ]);

viewport can be both HTMLElement or jQuery object, meaning as for CSS selectors;

Return: object:
    viewport - reference to viewport element relations was calculated
    viewportWidth - viewport's width in pixels on calculation moment
    viewportHeight - viewport's height in pixels on calculation moment
    element - reference to element relations was calculated for
    elementWidth - element's width in pixels on calculation moment
    elementHeight - element's height in pixels on calculation moment
    top - distance in pixels from top border of element to top border of viewport
    bottom - distance in pixels from bottom border of element to bottom border of viewport
    left - distance in pixels from left border of element to left border of viewport
    right - distance in pixels from right border of element to right border of viewport

$('').viewport().inViewport([ threshold = 0 [, viewport = undefined ]]);

threshold must be an integer, meaning as for CSS selectors;
viewport can be both HTMLElement or jQuery object, meaning as for CSS selectors;

$('').viewport().getState([ threshold = 0 [, allowPartly = false [, viewport = undefined ]]]);

threshold must be an integer, meaning as for CSS selectors;
allowPartly must be a boolean, allow 'partly' states. Extra calculations will be made if true
viewport can be both HTMLElement or jQuery object, meaning as for CSS selectors;

Return:
object:
    inViewport - boolean, is element fully fits viewport
    vertical - string, element's state along vertical axis relatively to viewport
    horizontal - string, element's state along horizontal axis relatively to viewport
    viewport - reference to viewport element relations was calculated
    viewportWidth - viewport's width in pixels on calculation moment
    viewportHeight - viewport's height in pixels on calculation moment
    element - reference to element relations was calculated for
    elementWidth - element's width in pixels on calculation moment
    elementHeight - element's height in pixels on calculation moment
    top - distance in pixels from top border of element to top border of viewport
    bottom - distance in pixels from bottom border of element to bottom border of viewport
    left - distance in pixels from left border of element to left border of viewport
    right - distance in pixels from right border of element to right border of viewport

vertical field can be: inside, exceeds, top, partly-top, below, partly-below horizontal field can be: inside, exceeds, left, partly-left, right, partly-right

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].