不是上不去就是沒(méi)有暫停時(shí)間,哪里出問(wèn)題了?
在火狐里上不去一直抖,????Safari里就沒(méi)有暫停時(shí)間直接上去了。不知道哪里出問(wèn)題了。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
??? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
??? <title>自動(dòng)展開(kāi)</title>
??? <style type="text/css">
??????? body
??????? {
??????????? margin: 0 auto;
??????????? padding: 0;
??????? }
??????? a:focus
??????? {
??????????? outline: none;
??????? }
?????? ?
??????? #pn
??????? {
??????????? background: #e8e8e8;
??????????? height: 120px;
??????????? width: auto;
??????????? display: block;
??????????? margin: 0 auto;
??????????? padding: 5px;
??????????? text-align: center;
??????????? overflow:hidden;
??????? }
??????? .slide
??????? {
??????????? padding: 10px;
??????????? width: 960px;
??????????? margin: 0 auto;
??????????? background: gray;
??????????? text-align: center;
??????????? height: 40px;
??????????? line-height: 40px;
??????????? color: #fff;
??????? }
??? </style>
??? <script type="text/javascript">
?????? var h= 0;
????? ?
??????? //增加高度函數(shù)addH()
?????????? ?
??????? function addh() { ?
?????????? if(h < 300){
?????????????? h += 2;
???????????? document.getElementById("pn").style.height = h + "px";
?????????? }
?? ??? ???? else{
?? ??? ????? return ; ?
?? ??? ???? }
??????????? setTimeout("addh()",30);
??????? }
?????? ?
?????? //網(wǎng)頁(yè)加載完畢時(shí),調(diào)用增加高度函數(shù)addH(),等待5秒鐘后調(diào)用減少高度函數(shù)subh()。
??????? window.onload = function(){
??????????? addh();
??????????? setTimeout("subh()",5000);
??????? }
???? ?
???? ?
????? // 減少高度函數(shù)subH()
?? ?
??????? function subh() {
?????????? if(h > 0){
?????????????? h -= 2;
???????????? document.getElementById("pn").style.height = h + "px";
?????????? }
?? ??? ???? else{
?? ??? ????? return? ;
?? ??? ???? }
??????????? setTimeout("subh()",30);
??????? }
??????? ?
?????????? ?
?????????? ?
?????????? ?
??? </script>
</head>
<body>
??? <div id="pn">
??????? <h1>
??????????? 歡迎來(lái)到慕課網(wǎng)</h1>
??????? <h2>
??????????? 大幅廣告</h2>
??? </div>
??? <p class="slide">
??????? 慕課網(wǎng)歡迎你</p>
</body>
</html>
2018-08-15
function subh() {
?????????? if(h > 0){
?????????????? h -= 2;
???????????? document.getElementById("pn").style.height = h + "px";?
?????????? }
?? ??? ???? else{
?? ??? ????? return? ;?
?? ??? ???? }
??????????? setTimeout("subh()",30);
??????? }
將? h -= 2改成? h -= 5就沒(méi)問(wèn)題了
2017-03-15
你的速度設(shè)置有問(wèn)題,當(dāng)文檔加載完畢后,高度真的成300px了嗎?顯然不是,是192px,所以解決方案有2;其一是改變速度的變化值;其二是延遲文檔加載完畢后的時(shí)間去執(zhí)行subh函數(shù)
2016-07-04
沒(méi)問(wèn)題啊。