aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/htmlimageelement/index.html
blob: 34cf4d1a26bb15ce6fe35405b257766de49931a7 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
---
title: HTMLImageElement
slug: Web/API/HTMLImageElement
translation_of: Web/API/HTMLImageElement
---
<div>{{ApiRef}}</div>

<div>{{APIRef("HTML DOM")}}</div>

<p>Интерфейс <code><strong>HTMLImageElement</strong></code>  предоставляет специальные свойства и методы  (расширяя обычный интерфейс {{domxref("HTMLElement")}}  ) для управления вёрсткой и отображением элемента {{HTMLElement("img")}}</p>

<p>{{InheritanceDiagram(600,120)}} </p>

<h2 id="Свойства">Свойства</h2>

<p><em>Наследует свойства родителя, {{domxref("HTMLElement")}}.</em></p>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Имя</th>
   <th scope="col">Тип</th>
   <th scope="col">Описание</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>align</code> {{obsolete_inline}}</td>
   <td>{{domxref("DOMString")}}</td>
   <td>Указывает расположение картинки зависящее от окружающего контента. Возможные значения:  <code>"left"</code><code>"right"</code><code>"justify"</code>, и <code>"center"</code>.</td>
  </tr>
  <tr>
   <td><code>alt</code></td>
   <td>{{domxref("DOMString")}}</td>
   <td>Повторяет атрибут HTML {{htmlattrxref("alt", "img")}} указывающий на запасной контекст картинки.</td>
  </tr>
  <tr>
   <td><code>border</code> {{obsolete_inline}}</td>
   <td>{{domxref("DOMString")}}</td>
   <td>Ширина рамки вокруг картинки. Устарело и вместо него следует использовать свойство CSS {{cssxref("border")}}.</td>
  </tr>
  <tr>
   <td><code>complete</code> {{readonlyInline}}</td>
   <td>{{domxref("Boolean")}}</td>
   <td>Возвращает true, если браузер закончил загрузку картинки с ошибкой или успешно. Также возвращает true, когда не установлено значение  {{domxref("HTMLImageElement.src", "src")}}, во всех остальных случаях - false.</td>
  </tr>
  <tr>
   <td><code>crossOrigin</code></td>
   <td>{{domxref("DOMString")}}</td>
   <td>Является {{domxref("DOMString")}}, с настройками CORS для этого элемента изображения. Дополнительная информация: <a href="https://developer.mozilla.org/en-US/docs/HTML/CORS_settings_attributes">Атрибуты настроек CORS</a>.  </td>
  </tr>
  <tr>
   <td><code>currentSrc</code>{{readonlyInline}}{{experimental_inline}}</td>
   <td>{{domxref("DOMString")}}</td>
   <td>Возвращает {{domxref("DOMString")}} с URL-адресом текущего изображения (что может измениться, например, в ответ на запросы мультимедиа).</td>
  </tr>
  <tr>
   <td><code>height</code></td>
   <td><code>unsigned long</code></td>
   <td>Отражает атрибут {{htmlattrxref ("height", "img")}} HTML, указывая визуализированную высоту изображения в пикселях CSS.</td>
  </tr>
  <tr>
   <td><code>hspace</code> {{obsolete_inline}}</td>
   <td><code>long</code></td>
   <td>Space to the left and right of the image.</td>
  </tr>
  <tr>
   <td><code>isMap</code></td>
   <td>{{domxref("Boolean")}}</td>
   <td>Reflects the {{htmlattrxref("ismap", "img")}} HTML attribute, indicating that the image is part of a server-side image map.</td>
  </tr>
  <tr>
   <td><code>longDesc</code> {{obsolete_inline}}</td>
   <td>{{domxref("DOMString")}}</td>
   <td>URI of a long description of the image.</td>
  </tr>
  <tr>
   <td><code>lowSrc</code> {{obsolete_inline}}</td>
   <td>{{domxref("DOMString")}}</td>
   <td>A reference to a low-quality (but faster to load) copy of the image.</td>
  </tr>
  <tr>
   <td><code>name</code> {{obsolete_inline}}</td>
   <td>{{domxref("DOMString")}}</td>
   <td> </td>
  </tr>
  <tr>
   <td><code>naturalHeight</code> {{readonlyInline}}</td>
   <td><code>unsigned long</code></td>
   <td>Intrinsic height of the image in CSS pixels, if it is available; otherwise, <code>0</code>.</td>
  </tr>
  <tr>
   <td><code>naturalWidth</code> {{readonlyInline}}</td>
   <td><code>unsigned long</code></td>
   <td>Intrinsic width of the image in CSS pixels, if it is available; otherwise, <code>0</code>.</td>
  </tr>
  <tr>
   <td><code>src</code></td>
   <td>{{domxref("DOMString")}}</td>
   <td>Reflects the {{htmlattrxref("src")}} HTML attribute, containing the URL of the image.</td>
  </tr>
  <tr>
   <td><code>srcset</code> {{experimental_inline}}</td>
   <td> </td>
   <td> </td>
  </tr>
  <tr>
   <td><code>useMap</code></td>
   <td>{{domxref("DOMString")}}</td>
   <td>Reflects the {{htmlattrxref("usemap", "img")}} HTML attribute, containing a partial URL of a map element.</td>
  </tr>
  <tr>
   <td><code>vspace</code> {{obsolete_inline}}</td>
   <td><code>long</code></td>
   <td>Space above and below the image.</td>
  </tr>
  <tr>
   <td><code>width</code></td>
   <td><code>unsigned long</code></td>
   <td>Reflects the {{htmlattrxref("width", "img")}} HTML attribute, indicating the rendered width of the image in CSS pixels.</td>
  </tr>
  <tr>
   <td><code>x</code> {{readonlyInline}}{{non-standard_inline}}</td>
   <td><code>long</code></td>
   <td>The horizontal offset from the nearest layer. (Mimic an old Netscape 4 behavior)</td>
  </tr>
  <tr>
   <td><code>y</code> {{readonlyInline}}{{non-standard_inline}}</td>
   <td><code>long</code></td>
   <td>The vertical offset from the nearest layer. (Mimic an old Netscape 4 behavior)</td>
  </tr>
 </tbody>
</table>

<h2 id="Методы">Методы</h2>

<p><em>Наследует методы родителя, {{domxref("HTMLElement")}}.</em></p>

<dl>
 <dt>{{domxref("HTMLImageElement.Image()")}}</dt>
 <dd>The <code>Image()</code> constructor, taking two optional <code>unsigned</code> <code>long</code>, the width and the height of the resource, creates an instance of <code>HTMLImageElement</code> not inserted in a DOM tree.</dd>
</dl>

<h2 id="Пример">Пример</h2>

<pre class="brush: js">var img1 = new Image(); // Конструктор HTML5
img1.src = 'image1.png';
img1.alt = 'alt';
document.body.appendChild(img1);

var img2 = document.createElement('img'); // Используем <a href="http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/html/nsIDOMHTMLImageElement.idl" title="http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/html/nsIDOMHTMLImageElement.idl">HTMLImageElement</a>
img2.src = 'image2.jpg';
img2.alt = 'alt text';
document.body.appendChild(img2);

// выбираем первое изображение на странице
alert(document.images[0].src);
</pre>

<h2 id="Спецификации">Спецификации</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Спецификация</th>
   <th scope="col">Статус</th>
   <th scope="col">Комментарий</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', "text-level-semantics.html#the-a-element", "HTMLAnchorElement")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>The following property has been added: <code>srcset</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', "text-level-semantics.html#the-a-element", "HTMLAnchorElement")}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>A constructor (with 2 optional parameters) has been added.<br>
    The following properties are now obsolete: <code>name</code>, <code>border</code>, <code>align</code>, <code>hspace</code>, <code>vspace</code>, and <code>longdesc</code>.<br>
    The following properties are now <code>unsigned long</code>, instead of <code>long</code>: <code>height</code>, and <code>width</code>.<br>
    The following properties have been added: <code>crossorigin</code>, <code>naturalWidth</code>, <code>naturalHeight</code>, and <code>complete</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 HTML', 'html.html#ID-17701901', 'HTMLImgElement')}}</td>
   <td>{{Spec2('DOM2 HTML')}}</td>
   <td>The <code>lowSrc</code> property has been removed.<br>
    The following properties are now <code>long</code>, instead of <code>DOMString</code>: <code>height</code>, <code>width</code>, <code>hspace</code>, and <code>vspace</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM1', 'level-one-html.html#ID-17701901', 'HTMLImgElement')}}</td>
   <td>{{Spec2('DOM1')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Совместимость">Совместимость</h2>

<p>{{Compat("api.HTMLImageElement")}}</p>

<h2 id="Смотрите_также">Смотрите также</h2>

<ul>
 <li>Элемент HTML, реализующий этот интерфейс: {{HTMLElement("img")}}</li>
</ul>