1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/visibleinviewport.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-08-11 23:23:12 -04:00
define(['dom'], function (dom) {
2016-01-10 12:37:11 -05:00
/**
* Copyright 2012, Digital Fusion
* Licensed under the MIT license.
* http://teamdf.com/jquery-plugins/license/
*
* @author Sam Sehnert
* @desc A small plugin that checks whether elements are within
* the user visible viewport of a web browser.
* only accounts for vertical position, not horizontal.
*/
2016-08-28 14:59:14 -04:00
function visibleInViewport(elem, partial, thresholdX, thresholdY) {
2016-01-10 12:37:11 -05:00
thresholdX = thresholdX || 0;
thresholdY = thresholdY || 0;
2016-03-11 22:29:37 -05:00
if (!elem.getBoundingClientRect) {
return true;
}
2016-08-28 14:59:14 -04:00
var windowSize = dom.getWindowSize();
2016-03-11 22:29:37 -05:00
var vpWidth = windowSize.innerWidth,
vpHeight = windowSize.innerHeight;
2016-01-10 12:37:11 -05:00
// Use this native browser method, if available.
var rec = elem.getBoundingClientRect(),
tViz = rec.top >= 0 && rec.top < vpHeight + thresholdY,
bViz = rec.bottom > 0 && rec.bottom <= vpHeight + thresholdY,
lViz = rec.left >= 0 && rec.left < vpWidth + thresholdX,
rViz = rec.right > 0 && rec.right <= vpWidth + thresholdX,
vVisible = partial ? tViz || bViz : tViz && bViz,
hVisible = partial ? lViz || rViz : lViz && rViz;
return vVisible && hVisible;
}
return visibleInViewport;
});