不做浮躁的人
正在行走的人...
posts - 171,  comments - 51,  trackbacks - 0

我们希望flex web能够充分利用客户浏览器的内容显示空间,也希望当用户的浏览器内容空间太小的情况下不至于将我们的flex web压缩的难看,因此,我们希望flex web有个minHeight和minwidth。而width和height能够充分适应屏幕。花了几个小时解决,记载下:

1、在swfobject.js中填充代码:

function addResizeEvent(fn) {
        if (typeof win.addEventListener != UNDEF) {
            win.addEventListener("resize", fn, false);
        }
        else if (typeof doc.addEventListener != UNDEF) {
            doc.addEventListener("resize", fn, false);
        }
        else if (typeof win.attachEvent != UNDEF) {
            addListener(win, "onresize", fn);
        }
        else if (typeof win.onresize == "function") {
            var fnOld = win.onresize;
            win.onresize = function() {
                fnOld();
                fn();
            };
        }
        else {
            win.onresize = fn;
        }
    }

为了用swfobject.addResizeEvent,在swfobject原型定义上增加一行代码:

addResizeEvent: addResizeEvent,


2、修改html template,增加:

    var appSwf=null;
            var minHeight=600;
            var minWidth=900;
           
            swfobject.addLoadEvent(function(){
                appSwf=swfobject.getObjectById("${application}");
                adjustAppSwfSize();
            });
           
            swfobject.addResizeEvent(function(){
                adjustAppSwfSize();
            });

            //调整Flex app的大小。
            function adjustAppSwfSize(){
                if (appSwf!=null){
                    if (getBrowserContentWidth()<minWidth){
                        if (appSwf.width!=minWidth){
                            appSwf.width=minWidth;
                        }
                    }else if (appSwf.width!="100%"){
                        appSwf.width="100%";
                    }


                    if (getBrowserContentHeight()<minHeight){
                        if (appSwf.height!=minHeight){
                            appSwf.height=minHeight;
                        }
                    }else if (appSwf.height!="100%"){
                        appSwf.height="100%";
                    }                   
                }
            }

            //得到浏览器内容区宽度
            function getBrowserContentWidth(){
                 if (document.documentElement && document.documentElement.clientWidth) {
                        return document.documentElement.clientWidth;
                 } else if (document.body) {
                        return document.body.clientWidth;
                 }
            }
            //得到浏览器内容区高度
            function getBrowserContentHeight(){
                 if (document.documentElement && document.documentElement.clientHeight) {
                        return document.documentElement.clientHeight;
                 } else if (document.body) {
                        return document.body.clientHeight;
                 }
            }


以上代码目前的浏览器都跨了。我很久不写js代码了,生疏了。

posted on 2010-11-11 16:46 不做浮躁的人 阅读(2333) 评论(0)  编辑  收藏 所属分类: flex

只有注册用户登录后才能发表评论。


网站导航:
 

<2010年11月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(8)

随笔分类(31)

随笔档案(75)

文章分类(1)

文章档案(3)

搜索

  •  

最新评论

阅读排行榜

评论排行榜