繁体   English   中英

延迟直到满载

[英]Delay until fully loaded

我的页面中有一个时钟,加载速度非常快,但是加载时有一个瞬间,您可以看到它停止了。 我想让它仅在完全加载时显示。

这是时钟的代码:

<style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }

    #clock {
        position: relative;
        width: 500px;
        height: 480px;
        background: url(images/clockface.png);
        list-style: none;
        }

    #sec, #min, #hour {
        position: absolute;
        width: 30px;
        height: 600px;
        top: 0px;
        left: 225px;
        }

    #sec {
        background: url(images/sechand.png);
        z-index: 3;
        }

    #min {
        background: url(images/minhand.png);
        z-index: 2;
        }

    #hour {
        background: url(images/hourhand.png);
        z-index: 1;
        }

    p {
        text-align: center; 
        padding: 10px 0 0 0;
        }
</style>

<script type="text/javascript">
    $(document).ready(function() {
          setInterval( function() {
          var seconds = new Date().getSeconds();
          var sdegree = seconds * 6;
          var srotate = "rotate(" + sdegree + "deg)";
          $("#sec").css({"-moz-transform" : srotate, "-webkit-transform" : srotate});
          }, 1000 );
          setInterval( function() {
          var hours = new Date().getHours();
          var mins = new Date().getMinutes();
          var hdegree = hours * 30 + (mins / 2);
          var hrotate = "rotate(" + hdegree + "deg)";
          $("#hour").css({"-moz-transform" : hrotate, "-webkit-transform" : hrotate}); 
          }, 1000 );
          setInterval( function() {
          var mins = new Date().getMinutes();
          var mdegree = mins * 6;
          var mrotate = "rotate(" + mdegree + "deg)";
          $("#min").css({"-moz-transform" : mrotate, "-webkit-transform" : mrotate}); 
          }, 1000 );
    }); 
</script>

谢谢

<ul id="clock" style="visibility: hidden">  <!-- this is so the browser computes the position of the element but doesn't show it just yet -->
    <li id="sec"></li>
    <li id="hour"></li>
    <li id="min"></li>
</ul>

然后:

<script type="text/javascript">
    window.onload = function() { // this will be run when the whole page is loaded
        document.getElementById("clock").style.visibility = "display";
    };

</script>

div没有load事件。

在准备好DOM之后,我会隐藏时钟...

document.getElementById("clock").style.display = 'none';

...然后在时钟的代码的结束时,当它完成时,我会设定其显示到block ...

document.getElementById("clock").style.display = 'block';

...或inline如果更适合您的情况)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM