dojo borderlayout显示所有内容,闪烁然后正确重绘

时间:2010-03-05 15:32:58

标签: dojo dijit.layout

我使用Borderlayout从dojo站点复制了一个示例。但是,当我在浏览器中加载时,将显示所有部分的整个数据。几秒钟后,内容为referh,数据显示正确。

这是我复制的代码。谢谢你的帮助

<head>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dijit/themes/tundra/tundra.css">
    <style type="text/css">
        body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
    </style>
    <style type="text/css">
        html, body { width: 100%; height: 100%; margin: 0; } #borderContainer
        { width: 100%; height: 100%; }
    </style>
</head>

<body class="tundra ">
    <div dojoType="dijit.layout.BorderContainer" design="sidebar" gutters="true"
    liveSplitters="true" id="borderContainer">
        <div dojoType="dijit.layout.ContentPane" splitter="true" region="leading"
        style="width: 100px;">
            Hi
        </div>
        <div dojoType="dijit.layout.ContentPane" splitter="true" region="center">
            Hi, I'm center
        </div>
    </div>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js"
djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
    dojo.require("dijit.layout.ContentPane");
    dojo.require("dijit.layout.BorderContainer");
</script>
<!-- NOTE: the following script tag is not intended for usage in real
world!! it is part of the CodeGlass and you should just remove it when
you use the code -->
<script type="text/javascript">
    dojo.addOnLoad(function() {
        if (window.pub) {
            window.pub();
        }
    });
</script>

2 个答案:

答案 0 :(得分:3)

这看起来有点颠倒:你应该把你的javascripts放在head部分并首先加载dojo库。这不是你的问题。

当页面加载时,dojo会加载您“dojo.require”的所有模块,然后解析包含属性“dojoType”的所有标记并处理它们以进行渲染,这需要时间。

因此,您所看到的闪烁是解析小部件之前和之后的页面之间的差异。

您应该添加预加载器div并在解析页面后将其隐藏(请参阅this示例)。

这就是你的例子的样子:

<html>
    <head>

        <title>Preloader example</title>

        <!– every Dijit component needs a theme –>
        <link rel="stylesheet"
                href="http://o.aolcdn.com/dojo/1.4/dijit/themes/soria/soria.css">
        <style type="text/css">
                #preloader,
                body, html {
                        width:100%; height:100%; margin:0; padding:0;
                }
               #preloader {
                                  width:100%; height:100%; margin:0; padding:0;
                                  background:#fff
                                    url(’http://search.nj.com/media/images/loading.gif’)
                                    no-repeat center center;
                                    position:absolute;
                                    z-index:999;
                                }
                #borderContainer {
                        width:100%; height:100%;
                }


        </style>

        <!– load Dojo, and all the required modules –>
        <script src="http://o.aolcdn.com/dojo/1.4/dojo/dojo.xd.js"></script>
        <script type="text/javascript">
                var hideLoader = function(){
                                dojo.fadeOut({
                                        node:"preloader",
                                        onEnd: function(){
                                                dojo.style("preloader", "display", "none");
                                        }
                                }).play();
                        }
                        dojo.addOnLoad(function(){
                                // after page load, load more stuff (spinner is already spinning)
                                dojo.require("dijit.layout.BorderContainer");
                                dojo.require("dijit.layout.ContentPane");
                                dojo.require("dojo.parser");

                                // notice the second onLoad here:
                                dojo.addOnLoad(function(){
                                        dojo.parser.parse();
                                        hideLoader();
                                });
                        });

        </script>
    </head>
    <body class="soria">
        <div id="preloader"></div>
        <div dojoType="dijit.layout.BorderContainer" id="borderContainer" design="sidebar" gutters="true" liveSplitters="true">
                <div dojoType="dijit.layout.ContentPane" splitter="true" region="leading" style="width: 100px;">Hi</div>
                <div dojoType="dijit.layout.ContentPane" splitter="true" region="center">I'm Center</div>
        </div>
    </body>
</html>

答案 1 :(得分:1)

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js"></script>

if(dojo.isIE){
    addEvent(window, 'load', function(event) {
        dojo.parser.parse();
    });
}else{
    dojo.addOnLoad(function(){
        dojo.addOnLoad(function(){
            dojo.parser.parse();
        });
    });
}
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}

禁用parseOnLoad并手动添加事件以解析小部件,即。