The SVGRect
represents a rectangle. Rectangles consist of an x and y coordinate pair identifying a minimum x value, a minimum y value, and a width and height, which are constrained to be non-negative.
AnSVGRect
object can be designated as read only, which means that attempts to modify the object will result in an exception being thrown.
This interface also inherits properties from its parent, SVGGeometryElement
.
SVGRect.x
Read only
0
were specified.SVGRect.y
Read only
0
were specified.SVGRect.width
Read only
SVGRect.height
Read only
Exceptions on setting: A DOMException
with the code NO_MODIFICATION_ALLOWED_ERR
is raised on an attempt to change the value of a read-only attribute.
This interface also inherits properties from its parent, SVGGeometryElement
.
Here is a simple usage of rect interface. (Changing the color of the rect interface on every click)
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect width="300" height="100" id="myrect" onclick="doRectClick()" style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)" /> <text x="60" y="40" fill="white" font-size="40" onclick="doRectClick();">Click Me</text> </svg>
function doRectClick(){ var myrect = document.getElementById('myrect'); var r = Math.floor(Math.random() * 255); var g = Math.floor(Math.random() * 255); var b = Math.floor(Math.random() * 255); myrect.style.fill = 'rgb(' + r + ', ' + g + ' , ' + b + ')'; }
Click the rect.
Specification | Status | Comment |
---|---|---|
Scalable Vector Graphics (SVG) 2 The definition of 'SVGRectElement' in that specification. | Candidate Recommendation | Changed the inheritance from SVGElement to SVGGeometryElement and removed the implemented interfaces SVGTests , SVGLangSpace , SVGExternalResourcesRequired , SVGStylable , and SVGTransformable . |
Scalable Vector Graphics (SVG) 1.1 (Second Edition) The definition of 'SVGRectElement' in that specification. | Recommendation | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 1 | Yes | 1.5 | 9 | 8 | 3.1 |
height |
1 | ? | ? | ? | ? | ? |
width |
1 | ? | ? | ? | ? | ? |
x |
1 | ? | ? | ? | ? | ? |
y |
1 | ? | ? | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 1 | 18 | Yes | 4 | 8 | 3.1 | ? |
height |
1 | 18 | ? | ? | ? | ? | ? |
width |
1 | 18 | ? | ? | ? | ? | ? |
x |
1 | 18 | ? | ? | ? | ? | ? |
y |
1 | 18 | ? | ? | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SVGRect