问题
(function($)
{
$.fn.blink = function(options)
{
var defaults = { delay:5000 };
var options = $.extend(defaults, options);
return this.each(function()
{
var obj = $(this).find("img");
setInterval(function()
{
if($(obj).css("display") == "block")
{
$(obj).fadeOut('slow');
}
else
{
$(obj).fadeIn('slow');
}
}, options.delay);
});
}
}(jQuery))
$('.blink').blink();
HTML:
<a href="#" class="blink">
<img src="image.png" alt="some image" />
</a>
This script removes image with transition effect, and then shows it back. So here are two steps: 1) hide, 2) show.
There is 5 seconds delay on each step, it should be only when image is visible.
How do I remove delay from the hide step? There should not by any delay when image is unvisible.
Code is available on JsFiddle
Its a circle script, once fadeIn/Out is done, it should be started again.
Thanks.
回答1:
To remove the delay after fadeOut
, just chain the calls instead of calling them on their own interval:
$(obj).fadeOut('slow').fadeIn('slow');
I made some simplifications to the code: http://jsfiddle.net/vcWDy/2/
回答2:
UPDATE: here you go: http://jsfiddle.net/ifaour/Sj5sX/
I'm all ears for the jQuery Gurus for notes and improvements..
UPDATE 2: or http://jsfiddle.net/ifaour/tzdxX/
Sorry I got your question backward :) use:
$(obj).hide();
instead of:
$(obj).fadeOut('slow');
If you want to show it directly
use:
$(obj).show();
instead of:
$(obj).fadeIn('slow');
来源:https://stackoverflow.com/questions/4480490/remove-delay-on-hide