blob: e4e73b99f918efbe93923cfe8b9d44283572250f (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
---
title: Image()
slug: Web/API/HTMLImageElement/Image
tags:
- 图片对象
translation_of: Web/API/HTMLImageElement/Image
---
<div>{{ APIRef("HTML DOM") }}</div>
<p><strong><code>Image()</code></strong>函数将会创建一个新的{{domxref("HTMLImageElement")}}实例。</p>
<p>它的功能等价于 {{domxref("Document.createElement()", "document.createElement('img')")}}</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">Image(width, height)</pre>
<h3 id="参数">参数</h3>
<dl>
<dt>width</dt>
<dd>图片的宽度 (即 {{htmlattrxref("width", "img")}} 属性).</dd>
<dt>height</dt>
<dd>图片的高度 (即 {{htmlattrxref("height", "img")}} 属性).</dd>
</dl>
<h2 id="示例"><span style="line-height: 1.572;">示例</span></h2>
<pre class="brush: js">var myImage = new Image(100, 200);
myImage.src = 'picture.jpg';
document.body.appendChild(myImage);</pre>
<div>上面的代码相当于在 {{htmlelement("body")}}中定义了下面的HTML:</div>
<pre class="brush: html"><img width="100" height="200" src="picture.jpg">
</pre>
<div class="note">
<p><strong>Note</strong>: 无论构造函数中指定的大小是多少,都会加载整个位图. 如果在构造时指定了尺寸信息,那么将会反应在实例的 {{domxref("HTMLImageElement.width")}} 和 {{domxref("HTMLImageElement.height")}} 属性上。图像自身的CSS像素值将会反应在{{domxref("HTMLImageElement.naturalWidth")}} 和 {{domxref("HTMLImageElement.naturalHeight")}}属性。如果没有指定值,那么两个属性的值相同</p>
</div>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName("HTML WHATWG", "embedded-content.html#dom-image", "Image()")}}</td>
<td>{{spec2("HTML WHATWG")}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="兼容性">兼容性</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari (WebKit)</th>
</tr>
<tr>
<td>支持情况</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Android Webview</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
<th>Chrome for Android</th>
</tr>
<tr>
<td>支持情况</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
<td>{{compatversionunknown}}</td>
</tr>
</tbody>
</table>
</div>
|