定时jquery淡出-创建链接



我发现了这个很酷的jquery淡入淡出脚本,但我不太清楚如何更改脚本以使文本成为href链接(我想把它用作新闻提示)。我花了几个小时的时间,但我的jquery没有达到标准。例如,我试图将<a href="#">test line 1</a>放在textContentdiv中,但链接没有出现。下面的链接和代码复制以便于发布。有什么建议吗?我对其他想法持开放态度,但渐变效果很酷,我想保留它!感谢您的帮助!

http://jsfiddle.net/mplungjan/bWD4V/

<style type="text/css">
    div.textContent { display:none }
</style>
<div id="textMessage"></div>
<div class="textContent">test line 1 </div>
<div class="textContent">test line 2</div>
<script>
var cnt=0, texts=[];
// save the texts in an array for re-use
$(".textContent").each(function() {
texts[cnt++]=$(this).text();
});
function slide() {
  if (cnt>=texts.length) cnt=0;
  $('#textMessage').html(texts[cnt++]);
  $('#textMessage')
    .fadeIn('slow').animate({opacity: 1.0}, 5000).fadeOut('slow', 
     function() {
       return slide()
     }
  );      
}      
slide()
</script>

您需要使用"html"而不是"text":

var cnt=0, texts=[];
// save the texts in an array for re-use
$(".textContent").each(function() {
  texts[cnt++]=$(this).html();
});
function slide() {
  if (cnt>=texts.length) cnt=0;
  $('#textMessage').html(texts[cnt++]);
  $('#textMessage')
    .fadeIn('slow').animate({opacity: 1.0}, 5000).fadeOut('slow', 
     function() {
       return slide()
     }
  );      
}      
slide()

Fiddle:http://jsfiddle.net/bWD4V/132/

最新更新