当前位置: 首页 > 文档资料 > Snap.svg 英文文档 >

Element.attr(…)

优质
小牛编辑
134浏览
2023-12-01

Gets or sets given attributes of the element.

Parameters

  1. paramsobjectcontains key-value pairs of attributesyou want to set

or

Parameters

  1. paramstringname of the attribute

Returns: Element the current element

or

Returns: string value of attribute

Usage

el.attr({
fill: "#fc0",
stroke: "#000",
strokeWidth: 2, // CamelCase...
  "fill-opacity": 0.5, // or dash-separated names
  width: "*=2" // prefixed values
});
console.log(el.attr("fill")); // #fc0

Prefixed values in format "+=10" supported. All four operations ( +, -, * and /) could be used. Optionally you can use units for + and -: "+=2em".