2011-11-25 30 views

回答

3

此功能將啓動文件後準備計數。可以添加到你想要的任何地方。只要它在<script></script>標籤或不同的JS文件之間。

$(function(){ 
    $("#notification").delay(5000).fadeOut(2000); // the 2000 is the time the fadeOut will take to disapear. 
}); 

jsfidlle顯示此:http://jsfiddle.net/jGtTP/

+0

它的工作,但它仍然消失得相當快。我們能控制失蹤的時間嗎? – user1065673

+0

把'2000'改成MS想要的任何數字,這是'fadeOut'淡出的時間。 – Niels

+0

這正是我所需要的。謝謝。 – user1065673

-1
setTimeout(function() { 
    $('#notification').attr('style', 'display: none;'); 
}), 5000); 
4
$('#notification').delay(5000).fadeOut(); 

你會在JavaScript塊添加這種,這種方式:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" 
     type="text/javascript"> 
</script> 

<script type="text/javascript"> 

$(document).ready(function() { 

$('#notification').delay(5000).fadeOut(); 

} 

</script> 
+0

如果添加此,Leniel? – user1065673

+0

一般在您的網頁的標記... –

0

,如果你不想使用jQuery,你可以使用jsTween(在Google上搜索它)。我在網站上使用它進行動畫,它非常好,並且(在某些情況下)比jQuery淡出對手快得多。

opacityTween = new OpacityTween(document.getElementById('notification'),Tween.strongEaseInOut, 100, 0, 5); 
opacityTween.start() 

將淡出對象超過5秒