• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

JS Question: Delay triggering function

I have an overlay+ spinner setup for a site I'm building and I want to set it up so that when someone clicks a link, the overlay and spinner come up.

However, quite a few of the pages are practically instant loads, so by time the overlay renders, the new page is ready so it's just a meaningless flicker that appears.

Here's what I have now. This fires the overlay for everything. I just want it to fire if it takes more than 2 seconds to render the next page.

Code:
<script type="text/javascript">
$(document).ready(function() {
	$('a').click( function() {
		$(window).spin();} 
	);
});
</script>

Here's what I've found via googling, but this instead makes the overlay popup after 1 second of viewing the page... Any advise?


Code:
<script type="text/javascript">
	$(document).ready(function() {
		$('a').click( 
			setTimeout(function() {$(window).spin();}, 1000)
		);
	});
</script>
 
Last edited:
Are these links loading subframes? New windows? Invoking some sort of AJAX function?

For frames and windows, the proper way to do it would be to set up the spinner, load the page, then hook into the onload event of the frame or window to stop the spinner. This won't work if the frames or windows belong to a different domain however.

For an AJAX call, you start the spinner, fire the AJAX call, then stop the spinner in the callback function for the AJAX call.
 
Are these links loading subframes? New windows? Invoking some sort of AJAX function?

For frames and windows, the proper way to do it would be to set up the spinner, load the page, then hook into the onload event of the frame or window to stop the spinner. This won't work if the frames or windows belong to a different domain however.

For an AJAX call, you start the spinner, fire the AJAX call, then stop the spinner in the callback function for the AJAX call.

No it's literally for just straight links. If someone clicks on a link, (a href) I want an overlay with spinner to come up, but I just want it to wait 1 second before it does since many of the pages will load instantly. For those pages, the overlay just flickers and doesn't fully render because the new page is already fetched and rendered.
 
No it's literally for just straight links. If someone clicks on a link, (a href) I want an overlay with spinner to come up, but I just want it to wait 1 second before it does since many of the pages will load instantly. For those pages, the overlay just flickers and doesn't fully render because the new page is already fetched and rendered.

Let me rephrase my question. Are your links targeting a subframe or new window? Or are you reloading the entire top window?
 
Back
Top