加入收藏 | 设为首页 | 会员中心 | 我要投稿 河北网 (https://www.hebeiwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > 正文

documentElement常识汇总

发布时间:2018-09-14 13:20:28 所属栏目:创业 来源:取得当前浏览器窗口的高度和宽度 解决文案: script t
导读:题目来历: 取适合前赏识器窗口的高度和宽度 办理文案: script type=text/javascript //from ppk (http://www.jr.pl/www.quirksmode.org/viewport/compatibility.html) var x,y; if (self.innerHeight) // all except Explorer { x = self.innerWidth; y = s
题目来历:
取适合前赏识器窗口的高度和宽度

办理文案:
<script type="text/javascript">
//from ppk (http://www.jr.pl/www.quirksmode.org/viewport/compatibility.html)
var x,y;
if (self.innerHeight) // all except Explorer
{
x = self.innerWidth;
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
x = document.documentElement.clientWidth;
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
x = document.body.clientWidth;
y = document.body.clientHeight;
}
</script>

办理进程:
关于document.documentElement相干表明:

w3c:This is a convenience attribute that allows direct access to the child node that is the root element of the document. For HTML documents, this is the element with the tagName "HTML".[译:他是一个可以很是便捷的指向文档的根结点元素,好比HTML文档中指的是HTML标签]
mozilla developer:Returns the Element that is the root element of the document (for example, the <html> element for HTML documents). [译:返回文档的根结点元素,如HTML文档的<html>]
MSDN:Gets a reference to the root node of the document.[译:获取对赏识器的DOCUMENT元素的引用.(form MSDN中国)]

The CSSOM View Module节选并本身的译文(翻译不妥之处,接待指正)

I have doubts about the WindowView interface, which contains ancient properties such as innerWidth.
我猜疑WindowView的接口,如他包括一些很是老的要领,如innerWidth.

The problem is that innerWidth/Height and pageXOffset/pageYOffset are essentially doubles: they report the same information as document.documentElement.clientWidth/Height and document.documentElement.scrollTop/Left: the inner width of the viewport (browser window) and the scrolling offset of the document.
题目是innerWidth/Height和pageXOffset/pageYOffset有双重特征,document.documentElement.clientWidth/Height和document.documentElement.scrollTop/Left也给出了同样的信息:赏识器内部窗口和文档的转动条偏移.

Since we already have that information available, why repeat it? The only reason would be that there might be situations where the documentElement does not span the entire viewport, but as far as I know these situations don't exist nowadays, and frankly I wonder if they'll ever exist.
既然我们获得了有用的信息,为何又要一再呢?这独一的缘故起因也许是办理documentElement不能超过整个窗口,但据我所知这个题目本日已办理了,我还想知道是否他曾经就存在过这个题目.

I created a quick test that gives the root <html> element a wide margin and a border. Clicking outside the border still reports the <html> element as target, and document.documentElement.clientWidth and window.innerWidth report the same number of pixels in all browsers.
我做了一个示例,给标签<html>增进了margin和border.单击border外围地区,同样表现<html>标签存在,而且document.documentElement.clientWidth和 window.innerWidth在每个赏识器上都表现同样的像素巨细.

So even though the root element may appear to cover only part of the viewport, JavaScript still acts as if it covers the entire viewport. That makes sense: there is no block-level element that contains the root element (or the root element wouldn't be the root element).
纵然根元素也许包围了窗口的一部门,他包围整个窗口时,javascript依然表现他的存在.那么结论是-没有块级元素能包括根元素.

The other properties of the window view, outerWidth/Height and screenX/Y, are mostly useless. They've been around since Netscape 3, and in the ten years I've been writing scripts I've never needed to use either of them.
window的其余属性,outerWidth/Height和screenX/Y,根基上也是无效的.他在Netscape 3的时辰用的很是普及,最近几年我写剧本的时辰再也没有效到他们了.

For al these reasons I'm wondering if the WindowView shouldn't be scrapped outright. It just serves no purpose.
由于一些其余缘故起因我猜疑是不是应该废弃WindowView呢.但这无济于事!

(编辑:河北网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读