aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlimageelement/image
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/htmlimageelement/image
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/htmlimageelement/image')
-rw-r--r--files/zh-cn/web/api/htmlimageelement/image/index.html111
1 files changed, 111 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/htmlimageelement/image/index.html b/files/zh-cn/web/api/htmlimageelement/image/index.html
new file mode 100644
index 0000000000..e4e73b99f9
--- /dev/null
+++ b/files/zh-cn/web/api/htmlimageelement/image/index.html
@@ -0,0 +1,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">&lt;img width="100" height="200" src="picture.jpg"&gt;
+</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>