jQuery setTimeout

In: JavaScript

July 22nd, 2010.

In order to make certain jQuery function run after some amount of time, you can use setTimeout – a JavaScript function. Here is a snippet that will remove loading mask from your page, one second after a website was loaded.

1
2
3
4
5
jQuery(document).ready(function () {
	setTimeout( function() {
		jQuery('#loading_mask').hide();
	}, 1000 );
});

Note: You can setup loading mask to cover your whole website, or just some part (image gallery for example). This way you can achieve nice effect so user won’t see loading images.

Written by

Dejan is pragmatic software developer with Master's Degree in Computer Science. He is currently based in Belgrade (Serbia).