ACT reveal code

//  ACT REVEAL
/* ======================================= v 0.4.1
 @ target		selector	the target elements
   ======================================= */

function ACTreveal( target ){
	target = target || '[class*="A-reveal"]';

	let revealCheck = function(){
		$( target ).each(function(idx, cur){
			
			new checkElement( cur );
		})
	}
		
	function checkElement( cur ){
		cur = $( cur );
		let winTop    	= parseInt( $(window).scrollTop() );
		let winBottom 	= parseInt( window.innerHeight ) + winTop;
		
		
		let vis = {
			top : false,
			mid : false,
			bottom : false,
		}
		let objHeight = cur.attr('data-height') || cur.outerHeight();
		let objTop    = cur.attr('data-top') || cur.offset().top;
		let objBottom = parseInt( objTop ) + parseInt( objHeight ) ;
		let objMid    = parseInt( objTop ) + ( parseInt( objHeight ) / 2 ) ;
		let offset    = parseInt( cur.attr('data-offset') ) || 0;
		var hide 	   = false;
		if ( cur.attr('hide') || cur.hasClass('AR-hide') ) hide = true;

		objTop = parseInt( objTop );
 

		// reveal obj TOP
		if ( winBottom >= ( objTop + offset ) &&
			 winTop    <= ( objTop + offset ) ) {
			vis.top = true;
			cur.triggerHandler('reveal-top',[ vis ]);
		}
		// reveal obj MID
		if ( winBottom >= ( objMid + offset ) &&
			 winTop    <= ( objTop + offset ) ) {
			vis.mid = true;
			cur.triggerHandler('reveal-mid', [ vis ]);
		}
		// reveal obj BOTTOM
		if ( winBottom >= ( objBottom + offset ) &&
			 winTop    <= ( objBottom + offset )  ) {
			vis.bottom = true;
			cur.triggerHandler('reveal-bottom',[ vis ]);
		}

		if ( vis.top == true || vis.mid == true || vis.bottom == true )
			cur.triggerHandler('reveal',[ vis ]);



		if ( hide ) {
			//if ( this.visibility() == 'hidden' ) this.cur.hide();
			//else this.cur.show();
		}
			
 
	}
	
	
	setTimeout(function(){
		revealCheck();
		//$(document.body).on('touchmove', revealCheck);
		$( document ).scroll( revealCheck );
	}, 10)
	
}

Leave a Reply

Your email address will not be published. Required fields are marked *