为了账号安全,请及时绑定邮箱和手机立即绑定

不是上不去就是没有暂停时间,哪里出问题了?

在火狐里上不去一直抖,    Safari里就没有暂停时间直接上去了。不知道哪里出问题了。<!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>自动展开</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;
       
        //增加高度函数addH()
            
        function addh() {  
           if(h < 300){
               h += 2;
             document.getElementById("pn").style.height = h + "px";
           }
            else{
             return ;  
            }
            setTimeout("addh()",30);
        }
        
       //网页加载完毕时,调用增加高度函数addH(),等待5秒钟后调用减少高度函数subh()。
        window.onload = function(){
            addh();
            setTimeout("subh()",5000);
        }
      
      
      // 减少高度函数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>
            欢迎来到慕课网</h1>
        <h2>
            大幅广告</h2>
    </div>
    <p class="slide">
        慕课网欢迎你</p>
</body>
</html>

正在回答

3 回答

function subh() {
           if(h > 0){
               h -= 2;
             document.getElementById("pn").style.height = h + "px"; 
           }
            else{
             return  ; 
            }
            setTimeout("subh()",30);
        }


  h -= 2改成  h -= 5就没问题了

0 回复 有任何疑惑可以回复我~

你的速度设置有问题,当文档加载完毕后,高度真的成300px了吗?显然不是,是192px,所以解决方案有2;其一是改变速度的变化值;其二是延迟文档加载完毕后的时间去执行subh函数

0 回复 有任何疑惑可以回复我~

没问题啊。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
展开与收起效果
  • 参与学习       33640    人
  • 解答问题       179    个

通过效果展示与案例分析,教您实现不同类型的展开与收起效果

进入课程

不是上不去就是没有暂停时间,哪里出问题了?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号