2016-12-10 97 views
3

編程新手,我很高興能夠學習我所能做的一切。但是,目前有一個問題。我希望我的第一個標題淡出,但它絕對不行。下面的代碼:ID #firstheader我的H1 div不會淡出

$(document).ready(function() { 
 
    $("#firstheader").fadeOut('slow', 500); 
 
});
#firstheader { 
 
    font-family: Helvetica, Arial, sans-serif; 
 
    font-size: 20px; 
 
    color: red; 
 
    text-align: center; 
 
}
<!DOCTYPE HTML> 
 
<html> 
 
<head> 
 
<title>Global HypeBeast</title> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script type="text/javascript" src="script.js"></script> 
 
<link rel="stylesheet" type="text/css" href="stylesheet.css"/> 
 
    </head> 
 
    <body> 
 
    <div id="firstheader"> 
 
    <h1> 
 
    Global HypeBeast: Street Fashion WORLDWIDE 
 
    </h1> 
 
    </div> 
 
    </body> 
 
</html>

任何幫助,將不勝感激。這真是讓我難受。

+0

我的壞,我編輯可以說淡出。 –

回答

3

fadeOut()採取slow/fast或持續時間,而不是不都在同一時間,以便:

$("#firstheader").fadeOut('slow'); 

或者:

$("#firstheader").fadeOut(500); 

希望這有助於。

$(document).ready(function() { 
 
    $("#firstheader").fadeOut('slow'); 
 
});
#firstheader { 
 
    font-family: Helvetica, Arial, sans-serif; 
 
    font-size: 20px; 
 
    color: red; 
 
    text-align: center; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="firstheader"> 
 
    <h1> 
 
    Global HypeBeast: Street Fashion WORLDWIDE 
 
    </h1> 
 
</div>

0

您的目標是h1元素,但您已淡出容器格。相反,這樣做:

$(document).ready(function() { 
    $("#firstheader h1").fadeIn('slow'); 
}); 

並在CSS:

#firstheader h1{ 
    display:none; 
} 

由於問題是被編輯到fadeOut代替fadeIn

$("#firstheader h1").fadeOut('slow'); 
+3

CSS是不必要的,在父項上應用fadeOut會影響它的子項。這裏真正的問題是OP有無效的論點。 –

+0

如果還有其他元素和h1會怎樣。那麼一切都會受到影響。 – Jai

+0

是的,這是事實,但您說的方式似乎意味着這是OP代碼無法工作的問題的一部分。 –

2

好吧,如果你檢查fadeOut的文檔: http://api.jquery.com/fadeout/

看來,你可以說「慢」,或者手動把時間:)

乾杯,

編輯:修改根據羅裏McCrossan真正的評論我的回答。

+1

'fadeOut()'可以接受多個參數,但只有1個持續時間:) –

+0

哦,我的不好,寫得太快。它需要2個參數,但即使在閱讀文檔之後,我仍然沒有理由將「緩慢」和持續時間都放在一起。 –

+1

如果您同時使用.fadeOut('slow',500),則它不起作用,它將引發錯誤Uncaught TypeError:n。easing [this.easing]不是函數(...)。 fadeOut('slow')或fadeOut(500)都不是兩個。緩和應該是擺動,線性或其他插件。沒有寬鬆的「500」。 – TigOldBitties

1

供參考:.fadeOut()不採取兩個速度的論點。

$(document).ready(function() { 
 
    $("#firstheader").fadeOut(5000); 
 
});
#firstheader { 
 
    font-family: Helvetica, Arial, sans-serif; 
 
    font-size: 20px; 
 
    color: red; 
 
    text-align: center; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 
<div id="firstheader"> 
 
    <h1>Global HypeBeast: Street Fashion WORLDWIDE</h1> 
 
</div>