Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 839733 of CanvasGradient

  • Revision slug: Web/API/CanvasGradient
  • Revision title: CanvasGradient
  • Revision id: 839733
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment fix compat parsing error; cleanup

Revision Content

{{APIRef("Canvas API")}}

The CanvasGradient interface represents an opaque object describing a gradient. It is returned by the methods {{domxref("CanvasRenderingContext2D.createLinearGradient()")}} or {{domxref("CanvasRenderingContext2D.createRadialGradient()")}}.

Properties

Representing an opaque object, there is no exposed property.

Methods

There is no inherited method.

{{domxref("CanvasGradient.addColorStop()")}}
Adds a new stop, defined by an offset and a color, to the gradient. If the offset is not between 0 and 1 an INDEX_SIZE_ERR is raised, if the color can't be parsed as a CSS {{xref_csscolorvalue}}, a SYNTAX_ERR is raised.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', "the-canvas-element.html#canvasgradient", "CanvasGradient")}} {{Spec2('HTML WHATWG')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4.0 {{CompatGeckoDesktop("1.9.2")}} [1] 9.0 9.0 3.1
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.1 {{CompatGeckoMobile("1.9.2")}} [1] {{CompatUnknown}} 10.0 3.2

[1] Before Gecko 5.0, {{geckoRelease("5.0")}}, specifying non-finite values when adding color stops through a call to addColorStop() incorrectly throws SYNTAX_ERR instead of INDEX_SIZE_ERR.

See also

  • Creator methods in {{domxref("CanvasRenderingContext2D")}}.
  • The {{HTMLElement("canvas")}} element and its associated interface, {{domxref("HTMLCanvasElement")}}.

Revision Source

<div>{{APIRef("Canvas API")}}</div>

<p>The <code><strong>CanvasGradient</strong></code> interface represents an opaque object describing a gradient. It is returned by the methods {{domxref("CanvasRenderingContext2D.createLinearGradient()")}} or {{domxref("CanvasRenderingContext2D.createRadialGradient()")}}.</p>

<h2 id="Properties">Properties</h2>

<p><em>Representing an opaque object, there is no exposed property.</em></p>

<h2 id="Methods">Methods</h2>

<p><em>There is no inherited method.</em></p>

<dl>
 <dt>{{domxref("CanvasGradient.addColorStop()")}}</dt>
 <dd>Adds a new stop, defined by an <code>offset</code> and a <code>color</code>, to the gradient. If the offset is not between <code>0</code> and <code>1</code> an <code>INDEX_SIZE_ERR</code> is raised, if the color can't be parsed as a CSS {{xref_csscolorvalue}}, a <code>SYNTAX_ERR</code> is raised.</dd>
</dl>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', "the-canvas-element.html#canvasgradient", "CanvasGradient")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</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</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>4.0</td>
   <td>{{CompatGeckoDesktop("1.9.2")}} [1]</td>
   <td>9.0</td>
   <td>9.0</td>
   <td>3.1</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>2.1</td>
   <td>{{CompatGeckoMobile("1.9.2")}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>10.0</td>
   <td>3.2</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Before Gecko 5.0, {{geckoRelease("5.0")}}, specifying non-finite values when adding color stops through a call to <code>addColorStop()</code> incorrectly throws <code>SYNTAX_ERR</code> instead of <code>INDEX_SIZE_ERR</code>.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>Creator methods in {{domxref("CanvasRenderingContext2D")}}.</li>
 <li>The {{HTMLElement("canvas")}} element and its associated interface, {{domxref("HTMLCanvasElement")}}.</li>
</ul>
Revert to this revision