确保浏览器一次显示所有内容 [英] Make sure that the browser displays everything at once

查看:123
本文介绍了确保浏览器一次显示所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网站的图像和文字很重,连接速度慢,网络浏览器或低RAM的电脑,首先加载文本,然后图像需要一段时间才能加载。如何确保所有内容都显示在同一时间?



解决方案我已经想到:



<在PHP脚本的顶部和底部输出缓冲 - ob_start ob_end_flush 以确保在处理脚本之前没有发送任何内容。
  • 将整个DOM加载到JavaScript变量中,然后在加载完毕后将其重新发送。

  • 你认为哪个是最适合所有浏览器,甚至在慢电脑上的方法?我还没有在不同的平台和电脑上测试不同的速度和RAM。如果您有媒体重型网站的经验或有更好的方法,请告诉我要采取哪条路径。

    解决方案

    如果你可以依靠JavaScrip,有一个简单而有效的解决方案一次性显示所有内容


    1. 将白色层放在整个窗口的顶部。这将隐藏所有内容。

    2. 使用事件 window.onload 隐藏/删除覆盖层。

    3. 使用事件 window.onunload 再次显示隐藏层。

    图层:

      ... 
    < style>
    html,body {height:100%; }
    #hiding {
    display:block;
    width:100%;
    height:100%;
    position:absolute;
    顶部:0;
    左:0;
    background:#fff;
    }
    < / style>
    < / head>
    < body>
    < div id =hiding>< / div>
    ...

    JavaScript事件:

      ... 
    < script>
    window.onload = function(){
    document.getElementById('hiding')。style.display ='none';
    };
    window.onunload = function(){
    document.getElementById('hiding')。style.display ='block';
    };
    < / scritp>
    < / body>
    < / html>

    注意:不要将这些样式和JavaScript代码放入外部文件。



    注2:将加载微调框放置在隐藏图层的中间是很好的。您可以将其添加到 #hiding {...} 样式块: background:#fff url(/images/spinner.gif)center center;


    I have this website that is heavy in images and text and on slow connections, internet browsers or computers with low RAM the text is loaded first then the images take a while to load. How can I make sure that everything is displayed out at the same time?

    Solutions I've thought of:

    1. Output Buffering - ob_start and ob_end_flush at the top and bottom of my PHP script to make sure that nothing is sent before the script is processed.
    2. Loading the whole DOM in a Javascript variable then echoing it out after all is loaded.

    Which do you reckon is the best way that will work on all browsers and even on the slow computers? I haven't tested it on a variety of platforms and computers with varying speeds and RAM. If you have experience with media heavy sites or have a better way, please let me know which path to take.

    解决方案

    If you can afford to rely on JavaScrip, there is a simple and effective solution to show all the content at once.

    1. Put a white layer on top of the whole window. This hides all the content.
    2. Use event window.onload to hide/remove the covering layer.
    3. Use event window.onunload to show up again the hiding layer.

    The layer:

        ...
        <style>
            html, body{ height: 100%; }
            #hiding {
                display:    block;
                width:      100%;
                height:     100%;
                position:   absolute;
                top:        0;
                left:       0;
                background: #fff;
            }
        </style>
    </head>
    <body>
        <div id="hiding"></div>
        ...
    

    JavaScript events:

            ...
            <script>
                window.onload = function () {
                    document.getElementById('hiding').style.display = 'none';
                };
                window.onunload = function () {
                    document.getElementById('hiding').style.display = 'block';
                };
            </scritp>
        </body>
    </html>
    

    NOTE: Do NOT put those styles nor JavaScript code into external files.

    NOTE 2: It would be nice to place a loading spinner in the middle of the hiding layer. You can add this to #hiding { ... } style block: background: #fff url(/images/spinner.gif) center center;

    这篇关于确保浏览器一次显示所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆