sigil88
11/17/2016 - 10:57 AM

jquery / js scroll detect and trigger modal

jquery / js scroll detect and trigger modal

// made originally for bootstrap modal to appear on scroll up
// at this stage detects scroll up and down
		<!-- modal script on scroll-->
		<script type='text/javascript'>
			jQuery(document).ready(function($) {
				var $window			= $(window);
				var $currentScroll  = 0;
				
				$(window).scroll(function() {
					var $signupModal	= $('#signup');
					var $nextScroll 		= $(this).scrollTop();

					if ( $nextScroll > $currentScroll ) {

						console.log('scrolling down');
						console.log('currentScroll: ' + $currentScroll);
						console.log('nextScroll: ' + $nextScroll);
						$signupModal.modal("show");
					
					} else {
						console.log('scrolling up');
					}

					$currentScroll = $nextScroll;

					console.log('ok done, currentScroll is ' + $currentScroll);
		
				})

			});
		</script>