A jQuery plugin for detect if element is in device viewport.
<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- isVisible core JS file -->
<script src="jquery.isvisible.min.js"></script>
$(document).ready( function() {
$('.selector').isVisible();
});
isVisible accepts settings from an object of key/value pairs.
$('.selector').isVisible({
key: value,
key: value
});
Boolean: Add classes to the element when is visible a part ( .is-visible-top ecc.. )
Default: true
Boolean: Remove "ShowClass" classes when is out of viewport ( "false" is useful when animations are used only once )
Default: true
Integer: Change the location of the trigger point (All sides and all elements)
Default: 0
Integer: Change the location of the top side trigger point (All elements)
Default: 0
Integer: Change the location of the bottom side trigger point (All elements)
Default: 0
Integer: Change the location of the left side trigger point (All elements)
Default: 0
Integer: Change the location of the right side trigger point (All elements)
Default: 0
String: Class added to the element when all sides are in viewport
Default: is-visible
String: Class added to the element when left and right sides are in viewport
Default: is-visible-x
String: Class added to the element when top and bottom sides are in viewport
Default: is-visible-y
String: Class added to the element when top side is in viewport
Default: is-visible-top
String: Class added to the element when bottom side is in viewport
Default: is-visible-bottom
String: Class added to the element when left side is in viewport
Default: is-visible-left
String: Class added to the element when right side is in viewport
Default: is-visible-right
String: Name of the data attribute which sets an offset on all sides ( Works on sigle element )
Default: is-visible-offset
String: Name of the data attribute which sets a top offset ( Works on sigle element )
Default: is-visible-offset-top
String: Name of the data attribute which sets a bottom offset ( Works on sigle element )
Default: is-visible-offset-bottom
String: Name of the data attribute which sets a left offset ( Works on sigle element )
Default: is-visible-offset-left
String: Name of the data attribute which sets a right offset ( Works on sigle element )
Default: is-visible-offset-right
isVisible
: This event is triggered when element is in the viewport
visiblePart: Name of the side visible ( xy, x, y, top, bottom, left, right )
scrollDirectionY: Direction of the scroll on Y axis ( up, down)
scrollDirectionX: Direction of the scroll on X axis ( left, right)
$('.selector').on( 'isVisible', function( event, visiblePart, scrollDirectionY, scrollDirectionX ) {
if ( visiblePart == "y") {
// Your code here
}
});
Copyright (c) 2017 Fabio Quarantini