blob: 7fbcfb5266eedff415a3825e9f7733fe4ba01170 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
---
title: HTMLElement.offsetWidth
slug: Web/API/HTMLElement/offsetWidth
tags:
- API
- 参考
- 只读属性
- 属性
translation_of: Web/API/HTMLElement/offsetWidth
---
<div>{{ APIRef("HTML DOM") }}</div>
<p><code><strong>HTMLElement.offsetWidth</strong></code> 是一个只读属性,返回一个元素的布局宽度。一个典型的(译者注:各浏览器的offsetWidth可能有所不同)offsetWidth是测量包含元素的边框(border)、水平线上的内边距(padding)、竖直方向滚动条(scrollbar)(如果存在的话)、以及CSS设置的宽度(width)的值。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">var<var> offsetWidth</var> =<var>element</var>.offsetWidth;
</pre>
<p><code>intElemOffsetWidth</code> is a variable storing an integer corresponding to the <code>offsetWidth</code> pixel value of the element. <code>offsetWidth</code> 是一个只读属性。</p>
<div class="note">
<p>这个属性将会 round(四舍五入)为一个整数。如果你想要一个fractional(小数)值,请使用{{ domxref("element.getBoundingClientRect()") }}.</p>
</div>
<h2 id="示例">示例</h2>
<p><img alt="Image:Dimensions-offset.png" class="internal" src="/@api/deki/files/186/=Dimensions-offset.png"></p>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('CSSOM View', '#dom-htmlelement-offsetwidth', 'offsetWidth')}}</td>
<td>{{Spec2('CSSOM View')}}</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="备注">备注</h3>
<p><code>offsetWidth</code> 是一个 <abbr>DHTML</abbr> 对象模型中的属性,由微软 IE 浏览器首次引入。有时候它也可以称为一个元素的物理或图形尺寸,或者 border-box(译者注:即 CSS3中的 border-box 模型)的宽度。</p>
<h2 id="参见">参见</h2>
<ul>
<li>{{domxref("Element.clientWidth")}}</li>
<li>{{domxref("Element.scrollWidth")}}</li>
<li><a href="/en-US/docs/Determining_the_dimensions_of_elements">Determining the dimensions of elements</a></li>
</ul>
|