src/main/javascript/scroll/floatz.scroll.scroller.js
/**
 * Initialize intersection observer.
 * <p>
 *     Ensures that only one intersection observer is created and the observed target handler is registered.
 * </p>
 *
 * @param {Scroller} scroller Scroller
 * @param {DOMElement|Array} target Observed target element(s)
 * @private
 */
Initialize intersection observer.

Ensures that only one intersection observer is created and the observed target handler is registered.

@param {Scroller} scroller Scroller
@param {DOMElement|Array} target Observed target element(s)
@private
Initialize intersection observer . Ensures that only one intersection observer is created and the observed target handler is registered . @param { Scroller } scroller Scroller @param { DOMElement|Array } target Observed target element ( s ) @private
function _initIntersectionObserver(scroller, target) {
	if (scroller._observer === null) {
		scroller._observer = new IntersectionObserver((entries) => {
			entries.forEach((entry) => {
				scroller._observeHandlers.filter(handler => handler.target.origNode() === entry.target)
					.forEach((handler) => {
						handler.handler(entry);
					})
				;
				if (entry.isIntersecting && entry.intersectionRatio > 0.1  ) {
					scroller._scrollInHandlers.filter(handler => handler.target.origNode() === entry.target)
						.forEach((handler) => {
							handler.handler(entry);
						})
					;
				} else {
					scroller._scrollOutHandlers.filter(handler => handler.target.origNode() === entry.target)
						.forEach((handler) => {
							handler.handler(entry);
						})
					;
				}
			});
		}, {
			root: scroller.options().intersection.root,
			rootMargin : scroller.options().intersection.rootMargin,
			threshold: scroller.options().intersection.threshold
		});
	}
	let targets = Array.isArray(target) ? target : new Array(target);
	targets.forEach((target) => {
		scroller._observer.observe(target.origNode());
	});
}
function _initIntersectionObserver ( scroller , target ) { if ( scroller . _observer === null ) { scroller . _observer = new IntersectionObserver ( ( entries ) => { entries . forEach ( ( entry ) => { scroller . _observeHandlers . filter ( handler => handler . target . origNode ( ) === entry . target ) . forEach ( ( handler ) => { handler . handler ( entry ) ; } ) ; if ( entry . isIntersecting && entry . intersectionRatio > 0.1 ) { scroller . _scrollInHandlers . filter ( handler => handler . target . origNode ( ) === entry . target ) . forEach ( ( handler ) => { handler . handler ( entry ) ; } ) ; } else { scroller . _scrollOutHandlers . filter ( handler => handler . target . origNode ( ) === entry . target ) . forEach ( ( handler ) => { handler . handler ( entry ) ; } ) ; } } ) ; } , { root : scroller . options ( ) . intersection . root , rootMargin : scroller . options ( ) . intersection . rootMargin , threshold : scroller . options ( ) . intersection . threshold } ) ; } let targets = Array . isArray ( target ) ? target : new Array ( target ) ; targets . forEach ( ( target ) => { scroller . _observer . observe ( target . origNode ( ) ) ; } ) ; }
Initialize intersection observer.
Initialize intersection observer .
// FIXME Consider fixed header offsets // console.log(entry); // Run handlers for observed elements /* Fix: Avoid firing to early - see issue #27 */ // Run scroll-in handlers /////// Changed back again - want to know if the section is not intersected, e.g. when reloading the page at other position than the initial // } else if (!scroller._firstIntersection) { // Don´t fire scroll-out on first run when they were never visible // Run scroll-out handlers // scroller._firstIntersection = false; // TODO: Check what happens if same target is observed multiple times