JQuery Help

Soldato
Joined
8 Oct 2005
Posts
4,184
Location
Midlands, UK
Hi,

I have a for sale items panel on my site and make it subtely blink using the following:

Code:
$(".RedBox").fadeOut(2000).fadeIn(2000);

That all works fine, but happens whenever the page loads or a form is submitted, as its in the doc.ready listener and gets a bit annoying after a while :(

Is there any way to have this effect happen at set intervals of time, such as every x number of seconds?

Ta
 
Code:
$(".RedBox").fadeOut(2000, function() {
      setTimeout("", 10000);
      $(".RedBox").fadeIn(2000);
});

Would something like this work? Use the setTimeout to wait for a given time i.e. ten seconds here. So on every fade out it runs the function stated. I haven't much experience with jquery but did something similar using mootools with this function. I am not sure if this setTimeout will work though as no code is set for the first parameter.
 
Code:
$(function() {

  function fade() {
    $('.RedBox').fadeOut(2000).fadeIn(2000, fadeCallback);
    setTimeout(fade, 10000);
    };

  fade();

});
This will blink on page load then again every 10 seconds... i put it in a fade() function so it has a way of referring back to itself to queue up the next blink ;)
 
Where did fadeCallback come from? You don't need the setTimeout call to trigger fade if you're trying to use it as a callback to the fade animation.

This should do the trick:

Code:
$(function()
{
	var fadeInterval = 5000;
	var fadeDuration = 2000;
	
	function fade()
	{
		setTimeout('', fadeInterval);
		$('.RedBox').fadeOut(fadeDuration).fadeIn(fadeDuration, fade);
	};
	
	fade();
});

This will run the fade animation at 5 second intervals, starting 5 seconds after page load. Note that a complete cycle is 9 seconds: 2 for fade-out, 2 for fade-in, and another 5 until it starts again.

:)
 
yeah sorry i meant fade not fadeCallBack - use Inquisitor's code ;) - its better and more importantly it will work :p
 
Back
Top Bottom