定时jquery淡出 - 创建链接

时间:2013-08-28 21:24:27

标签: jquery hyperlink fadein fadeout

我发现这个很酷的jquery淡入/淡出脚本,但是我无法弄清楚如何改变脚本以使文本成为href链接(我想将它用作新闻自动收报机)。我花了几个小时摆弄,但我的jquery不符合标准。例如,我试图将<a href="#">test line 1</a>放在textContent div中,但链接不会出现。为方便起见,下面的链接和代码复制到发布。有什么建议?我对其他想法持开放态度,但淡化效果很酷,我想保留它!谢谢你的帮助!

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>

1 个答案:

答案 0 :(得分:0)

您需要使用“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()

小提琴:http://jsfiddle.net/bWD4V/132/