steveosoule
9/28/2015 - 6:28 PM

Trigger Event On Reveal of Element

Trigger Event On Reveal of Element

$(document).one('someTrigger', function(){
	console.log('Do something');
});

$(window).on('scroll', function(){
	var distanceUntilVisible = $('.some-element').position().top - (window.scrollY + window.innerHeight);
	console.log(distanceUntilVisible);
	if( distanceUntilVisible <= 400 ){
		$(document).trigger('someTrigger');
	}
});