【问题标题】:jquery document widthjquery 文档宽度
【发布时间】:2011-09-09 22:55:17
【问题描述】:

我用来设置一个 div 作为整个页面的掩码。

$(document).width();

但这在 IE 和 Firefox 之间的行为不同。在 IE 中它给出 796,而在 Firefox 中它给出 789。 当我将掩码的宽度应用为 $(document).width();

在 Firefox 中,面具适合屏幕。 但在 IE 中,下方会出现一个额外的滚动条。

我希望遮罩适合屏幕。请帮我处理这个。

window.width() 和 100% 在我调整窗口大小时无济于事。我不能使用 $('body') 因为我需要以相同的方式计算高度。

提前致谢。

【问题讨论】:

    标签: jquery asp.net html


    【解决方案1】:

    从字面上看,这是试错和搜索全世界的日子

    使用 pureJS 是因为连 jquery 都不能正确报告它!但需要 jquery 来识别浏览器。我用它来测量 iframe 中的正文——以避免跨域通信时出现滚动条。你可以稍微调整一下。但核心在那里

        if ( $.browser.msie ) { 
            var thisH = thisFrame.scrollHeight;     
            var thisW = thisFrame.scrollWidth;      
            }       
        else if ( $.browser.opera )
            {
            var thisW = thisFrame.scrollWidth;
            if (iframe.clientWidth > thisW ) { 
               thisW = 660; //These are custom- you can ignore it
            }
    
            var thisH = thisFrame.scrollHeight;
            if (iframe.clientHeight > thisH ) { 
                thisH = 550; //These are custom- you can ignore it
                  }
            }
        //All other clients
        else                
            {           
            var thisW = thisFrame.scrollWidth;
            if (iframe.clientWidth > thisW ) { 
            thisW = 660; //These are custom- you can ignore it
            }
    
            var thisH = $(thisFrame).height();
                if (iframe.clientHeight > thisH ) { 
                thisH = 550; //These are custom- you can ignore it
                }
            }       
    

    【讨论】:

      【解决方案2】:

      http://www.javascripter.net/faq/browserw.htm

      以下代码将变量 winW 和 winH 设置为实际的 浏览器窗口的宽度和高度,并输出宽度和 高度值。如果用户的浏览器很旧,那么 winW 和 winH 分别设置为 630 和 460。

      var winW = 630, winH = 460;
      if (document.body && document.body.offsetWidth) {
       winW = document.body.offsetWidth;
       winH = document.body.offsetHeight;
      }
      if (document.compatMode=='CSS1Compat' &&
          document.documentElement &&
          document.documentElement.offsetWidth ) {
       winW = document.documentElement.offsetWidth;
       winH = document.documentElement.offsetHeight;
      }
      if (window.innerWidth && window.innerHeight) {
       winW = window.innerWidth;
       winH = window.innerHeight;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-07-15
        • 1970-01-01
        • 2019-12-26
        • 2020-12-25
        • 2016-02-28
        相关资源
        最近更新 更多