IT & Programming

Trigger an event with JQuery when reach at the middle of the page

This jquery code snippet trigger an alert event when user scroll and reaches at middle of the page. Don't forget to add JQuery library before using this function.

Script

$(window).scroll(function () {

	if ($(window).scrollTop() > $(window).height() / 2) {
		
		alert('Reached at middle');
	}

});

Calling The Script

Script will be called automatically when you scroll and reach middle of the browser

Output

Alert Message 'Reached at middle'

Leave A comment

Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *