需要jquery闪烁文本只闪烁8秒,然后停止

我需要在8秒后停止闪烁文本。 一切都很完美,除了能够在8秒后停止它。 我是新手,需要帮助……

这是我正在使用的代码,请提供建议或在此代码中添加我需要在8秒后停止的代码:

 
text example

function blink(selector){ $(selector).fadeOut('slow', function(){ $(this).fadeIn('slow', function(){ blink(this); }); }); } blink('#msg');

谢谢

您可以尝试添加代码:

 var stopBlinking = false; setTimeout(function() { stopBlinking = true; }, 8000); function blink(selector) { $(selector).fadeOut('slow', function() { $(this).fadeIn('slow', function() { if (!stopBlinking) { blink(this); } else { $(this).hide(); } }); }); } 

看看这里的例子

  
text example

试试这个

 function blink(selector){ // all blink happen with 8 seconds interval setTimeout(function() { $(selector).fadeOut('slow', function(){ $(this).fadeIn('slow', function(){ blink(this); // recursive function will call after fadeIn finish }); }); }, 8000); // set interval to 8 seconds }