mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-12-18 09:11:16 +00:00
25 lines
724 B
JavaScript
25 lines
724 B
JavaScript
|
/**
|
||
|
* Create an observer for showing/hiding feature and for firing scroll event hooks.
|
||
|
* Based on Vector
|
||
|
*
|
||
|
* @param {Function} show functionality for when feature is visible
|
||
|
* @param {Function} hide functionality for when feature is hidden
|
||
|
* @return {IntersectionObserver}
|
||
|
*/
|
||
|
function initScrollObserver( show, hide ) {
|
||
|
/* eslint-disable-next-line compat/compat */
|
||
|
return new IntersectionObserver( ( entries ) => {
|
||
|
if ( !entries[ 0 ].isIntersecting && entries[ 0 ].boundingClientRect.top < 0 ) {
|
||
|
// Viewport has crossed the bottom edge of the target element.
|
||
|
show();
|
||
|
} else {
|
||
|
// Viewport is above the bottom edge of the target element.
|
||
|
hide();
|
||
|
}
|
||
|
} );
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
initScrollObserver
|
||
|
};
|