美文网首页
html定时器学习--模拟加载

html定时器学习--模拟加载

作者: 简鱼7819 | 来源:发表于2016-10-28 10:32 被阅读22次

效果图

加载时...

定时器跑完后

上代码

标签body中

<div id="load"class="loading"style="display:none">

        <div id="tip">页面正在加载请稍候!还有1秒</div>

</div>

<div id="zcContent"style="display:none">

       <p>hello world!!</p>

      <p>hello world!!</p>

      <p>hello world!!</p>

</div>

css样式

html,body{

height:100%;

margin:0;

padding:0;

}

.loading{

top:0;

left:0;

position:fixed;

width:100%;

height:100%;

background:rgba(0,0,0,0.7);

font-size:50px;

text-align:center;

color:#fff;

}

.loading div{

height:150px;

position:absolute;

left:0;

top:0;

bottom:0;

right:0;

margin:auto;

}

#zcContent{

position:absolute;

left:0;

top:0;

bottom:0;

right:0;

margin:auto;

font-size:50px;

text-align:center;

color:#222222;

background:#77d2c6;

}

script 标签调用timer

window.onload=function(){

            vari=5;

            timer=setInterval(function(){

                i--;

               if(i<=0){

                    clearInterval(timer);

                    document.getElementById('load').style['display']='none';

                   document.getElementById("zcContent").style["display"] ="block";

              }else{

                  document.getElementById('load').style['display']='block';

                  document.getElementById('tip').innerHTML='页面正在加载请稍候!还有'+i+'秒';

              };

        },1000);

};

定时器的开启setInterval以及清除clearInterval,另外注意div本身层级关系!!

刚学html,写这个文章既是自己积累也是分享跟我一样的初学者,非喜勿喷,谢谢!!!

相关文章

  • html定时器学习--模拟加载

    效果图 加载时... 定时器跑完后 上代码 标签body中 页面正在加载请稍候!还有1秒 hel...

  • WKWebView加载本地HTML失败 问题记录

    方案1、loadRequest:加载本地HTML 结果,模拟器加载正常,真机调试加载不成功,空白页; 方案2、 ...

  • 13

    定时器的基本用法 定时器动画 .bo...

  • 定时器内存

    问题描述 *在定时器加载序列帧的过程中加载图片的内存越来越大,定时器默认的内存释放在定时器加载完之后在进行释放。 ...

  • 运行循环 RunLoop

    观察RunLoop的活动阶段 定时器 图片加载 线程常驻 CD定时器

  • iOS RunLoop实践应用

    1.常驻线程 2.图片延迟加载(滑动时不加载) 3.定时器 定时器尽可能使用 dis

  • iOS富文本(NSAttributedString)UIText

    项目上要加载html格式的文本,学习一下富文本相关内容。 1.加载HTML标签文本 因为解析的数据里面有html标...

  • attributeString 属性

    项目上要加载html格式的文本,学习一下富文本相关内容。 1.加载HTML标签文本 因为解析的数据里面有html标...

  • HTML文档是边加载边解析、预解析

    HTML文档加载边解析 之前一直以为html是加载完之后才由html解析器进行解析的,学习了浏览器原理之后,才知道...

  • ios - webView的使用

    一. 创建: 二. 加载方式: 常用的网页加载方式 加载html格式的内容(html文件中加载和html格式字...

网友评论

      本文标题:html定时器学习--模拟加载

      本文链接:https://www.haomeiwen.com/subject/ghzsuttx.html