2013-08-28 38 views
0

我發現這個很酷的jquery淡入/淡出腳本,但我不能完全弄清楚如何改變腳本,使文本的href鏈接(我想用它作爲一個新聞新浪體育訊北京時間)。我花了幾個小時擺弄,但我的jquery沒有達到標準。例如,我試圖將<a href="#">test line 1</a>放入textContent div中,但鏈接不顯示。下面的鏈接和代碼複製到發佈以方便。有什麼建議麼?我接受其他想法,但淡入淡出效果很酷,我想保留這一點!感謝您的幫助!定時jQuery的淡出 - 創建鏈接

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> 

回答

0

你需要使用 「HTML」 代替 「文」:

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/