href - SVG: Scalable Vector Graphics 编辑

The href attribute defines a link to a resource as a reference URL. The exact meaning of that link depends on the context of each element using it.

Note: Specifications before SVG 2 defined an xlink:href attribute, which is now rendered obsolete by the href attribute.

Fifteen elements are using this attribute: <a>, <animate>, <animateMotion>, <animateTransform>, <discard>, <feImage>, <image>, <linearGradient>, <mpath>, <pattern>, <radialGradient>, <script>, <set>, <textPath>, and <use>

html, body, svg {
  height: 100%;
}
<svg viewBox="0 0 160 40" xmlns="http://www.w3.org/2000/svg">
  <a href="/wiki/"><text x="10" y="25">MDN Web Docs</text></a>
</svg>

In SVG

a

For <a>, href defines the location of the referenced object, expressed as a URL reference.

Value<url>
Default valueNone
AnimatableYes

animate, animateMotion, animateTransform, set

For the <animate>, <animateMotion>, <animateTransform>, and <set>, href defines a URL referring to the element which is the target of this animation element and which therefore will be modified over time.

The URL must point to exactly one target element which is capable of being the target of the given animation element. If the URL points to multiple target elements, if the given target element is not capable of being a target of the given animation element, or if the given target element is not part of the current document, then the animation element will not affect any target element. However, the animation element will still operate normally with regard to its timing properties. Specifically, TimeEvents are dispatched and the animation element can be used as syncbase in an identical fashion to when the URL refers to a valid target element.

If the href attribute or the deprecated xlink:href attribute is not provided, then the target element will be the immediate parent element of the current animation element. If both xlink:href and href are specified, the value of the latter attribute is used.

Refer to the descriptions of the individual animation elements for any restrictions on what types of elements can be targets of particular types of animations.

Except for any SVG-specific rules explicitly mentioned in this specification, the normative definition for this attribute is the SMIL Animation specification. In particular, see SMIL Animation: Specifying the animation target.

Value<url>
Default valueNone
AnimatableNo

discard

For <discard>, href defines a URL referring the target element to discard. See the definition of href on animation elements for details on identifying a target element.

Note: Unlike other animation elements, the <discard> element does not support the deprecated xlink:href attribute.

Note that if the target element is not part of the current SVG document fragment, then whether the target element will be removed or not is defined by the host language.

If the href attribute is not provided, then the target element will be the immediate parent element of the <discard> element.

Value<url>
Default valueNone
AnimatableNo

feImage

For <feImage>, href defines a URL referring to an image resource or to an element. If both, the xlink:href and the href attribute are specified, the latter overrides the former.

Value<url>
Default valueNone
AnimatableYes

image

For <image>, href defines a URL referring to the image to render.

Value<url>
Default valueNone
AnimatableYes

Example

html, body, svg {
  height: 100%;
}
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <image href="/files/2917/fxlogo.png" x="0" y="0" height="100" width="100"/>
</svg>

linearGradient

For <linearGradient>, href defines URL referring to a template gradient element; to be valid, the reference must be to a different <linearGradient> or <radialGradient> element.

Value<url>
Default valueNone
AnimatableYes

mpath

For <mpath>, href defines a URL referring to the <path> element or basic shape which defines the motion path.

Value<url>
Default valueNone
AnimatableNo

pattern

For <pattern>, href defines a URL referring to a different <pattern> element within the current SVG document. Any attributes which are defined on the referenced element which are not defined on this element are inherited by this element. If this element has no children, and the referenced element does (possibly due to its own href attribute), then this element inherits the children from the referenced element. Inheritance can be indirect to an arbitrary level; thus, if the referenced element inherits attributes or children due to its own href attribute, then the current element can inherit those attributes or children. On the <pattern> element, the href attribute is animatable.

Value<url>
Default valueNone
AnimatableYes

radialGradient

For <radialGradient>, href defines URL referring to a template gradient element; to be valid, the reference must be to a different <linearGradient> or <radialGradient> element.

Value<url>
Default valueNone
AnimatableYes

script

For <script>, href defines a URL referring to an external resource containing the script code.

Value<url>
Default valueNone
AnimatableNo

textPath

For <textPath>, href defines a URL referring to the <path> element or basic shape onto which the text will be rendered if no path attribute is provided. On the <textPath> element, the href attribute is animatable.

Value<url>
Default valueNone
AnimatableYes

use

For <use>, href defines a URL referring to an element or fragment within an SVG document to be cloned.

The <use> element can reference an entire SVG document by specifying an href value without a fragment. Such references are taken to be referring to the root element of the referenced document.

Value<url>
Default valueNone
AnimatableYes

Specifications

SpecificationStatusComment
Scalable Vector Graphics (SVG) 2
The definition of 'href for <a>' in that specification.
Candidate RecommendationDefines href for the <a> element.
SVG Animations Level 2
The definition of 'href for <animate>, <animateMotion>, <animateTransform>, and <set>' in that specification.
Editor's DraftDefines href for animation elements.
SVG Animations Level 2
The definition of 'href for <discard>' in that specification.
Editor's DraftDefines href for the <discard> element.
Filter Effects Module Level 1
The definition of 'href for <feImage>' in that specification.
Candidate RecommendationDefines href for the <feImage> element.
Scalable Vector Graphics (SVG) 2
The definition of 'href for <image>' in that specification.
Candidate RecommendationDefines href for the <image> element.
Scalable Vector Graphics (SVG) 2
The definition of 'href for <linearGradient>' in that specification.
Candidate RecommendationDefines href for the <linearGradient> element.
SVG Animations Level 2
The definition of 'href for <mpath>' in that specification.
Editor's DraftDefines href for the <mpath> element.
Scalable Vector Graphics (SVG) 2
The definition of 'href for <pattern>' in that specification.
Candidate RecommendationDefines href for the <pattern> element.
Scalable Vector Graphics (SVG) 2
The definition of 'href for <radialGradient>' in that specification.
Candidate RecommendationDefines href for the <radialGradient> element.
Scalable Vector Graphics (SVG) 2
The definition of 'href for <script>' in that specification.
Candidate RecommendationDefines href for the <script> element.
Scalable Vector Graphics (SVG) 2
The definition of 'href for <textPath>' in that specification.
Candidate RecommendationDefines href for the <textPath> element.
Scalable Vector Graphics (SVG) 2
The definition of 'href for <use>' in that specification.
Candidate RecommendationDefines href for the <use> element.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:68 次

字数:21122

最后编辑:8 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文