Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于Div height的Javascript,使其更快_Javascript_Html_Controls_Height - Fatal编程技术网

用于Div height的Javascript,使其更快

用于Div height的Javascript,使其更快,javascript,html,controls,height,Javascript,Html,Controls,Height,我使用以下脚本来控制具有ID的任何元素,在本例中,它是具有“包装器”ID的div: window.onload=window.onresize=函数ResizeIFrame(){ var div=document.getElementById(“包装器”); var myWidth=0,myHeight=0; if(typeof(window.innerWidth)=‘number’){ //非IE myWidth=window.innerWidth; myHeight=window.inner

我使用以下脚本来控制具有ID的任何元素,在本例中,它是具有“包装器”ID的div:

window.onload=window.onresize=函数ResizeIFrame(){ var div=document.getElementById(“包装器”); var myWidth=0,myHeight=0; if(typeof(window.innerWidth)=‘number’){ //非IE myWidth=window.innerWidth; myHeight=window.innerHeight-90; }else if(document.documentElement&(document.documentElement.clientWidth | | document.documentElement.clientHeight)){ //IE 6+处于“标准兼容模式” myWidth=document.documentElement.clientWidth; myHeight=document.documentElement.clientHeight-90; }else if(document.body&(document.body.clientWidth | | document.body.clientHeight)){ //IE4兼容 myWidth=document.body.clientWidth; myHeight=document.body.clientHeight-90; } div.style.width=myWidth+'px'; div.style.height=myHeight+'px'; } 在这个网站上,您可以看到它是如何工作的: 问题是,脚本等待页面完全加载以运行函数并调整窗口大小,或者等待用户手动调整窗口大小。 但是加载页面可能需要太长的时间,我希望脚本在窗口完全加载之前自动执行,以便用户可以在中间时间导航。 我尝试这样调用函数,但不起作用:

ResizeIFrame() ResizeIFrame() 救命啊! 再见

试试这个:

 function ResizeIFrame() {
            var div = document.getElementById("wrapper");
            var myWidth = 0, myHeight = 0;

            if (typeof (window.innerWidth) == 'number') {
                //Non-IE
                myWidth = window.innerWidth ;
                myHeight = window.innerHeight - 90;

            } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                //IE 6+ in 'standards compliant mode'
                myWidth = document.documentElement.clientWidth ;
                myHeight = document.documentElement.clientHeight - 90 ;
            } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight - 90;
            }
            div.style.width = myWidth + 'px';
            div.style.height = myHeight + 'px';
        }  

window.onload = window.onresize =  ResizeIFrame;

//Then you can just do:
ResizeIFrame(); //whenever you desire

直到所有图像和iFrame加载完毕,window.onload才会启动,这就是为什么所有主要的JS库都试图确定DOM何时准备好操作的原因,这通常会发生得更快。如果您不使用/不想使用其中一个库,这里有一个非常轻量级的跨浏览器DOM就绪帮助程序:

太好了,谢谢!,在等待window.onload时,我添加了window.onmouseover、window.onmouseclick和callfunction时间触发器
 function ResizeIFrame() {
            var div = document.getElementById("wrapper");
            var myWidth = 0, myHeight = 0;

            if (typeof (window.innerWidth) == 'number') {
                //Non-IE
                myWidth = window.innerWidth ;
                myHeight = window.innerHeight - 90;

            } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                //IE 6+ in 'standards compliant mode'
                myWidth = document.documentElement.clientWidth ;
                myHeight = document.documentElement.clientHeight - 90 ;
            } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight - 90;
            }
            div.style.width = myWidth + 'px';
            div.style.height = myHeight + 'px';
        }  

window.onload = window.onresize =  ResizeIFrame;

//Then you can just do:
ResizeIFrame(); //whenever you desire