zhangsanshi / issue-blog

It's a blog rather than issue
0 stars 0 forks source link

一个验证html渲染时机的办法 #35

Open zhangsanshi opened 7 years ago

zhangsanshi commented 7 years ago

链接

zhangsanshi commented 7 years ago

code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>测试</title>
    <script>
        function delayAsync(times) {
            var now = new Date() - 0;

            var delay = now + times;
            while (new Date() - 0 < delay) {

            }
            console.log(now);
        }
    </script>
    <style>
        body {
            color: #fff;
        }
    </style>
</head>
<body>
<script>
    console.log(new Date() - 0, 'body');
</script>
<style>
    body {
        background: #000;
    }
</style>
<div>1</div>
<script>
    delayAsync(2000);
</script>
<style>
    body {
        background: #ff0000;
    }
</style>
<div>22222222222222222222222222222222222222222222222</div>
<script>
    delayAsync(2000);
</script>
<style>
    body {
        background: #00ff00;
    }
</style>
<div>3</div>
<script>
    delayAsync(10000);
</script>
<script>
    console.log(new Date() - 0, 'body');
</script>
</body>
</html>