svg & stroke & style & class stroke-width, stroke



svg & stroke & style & class

svg selected style

methods

  1. style
  2. class, !important
  3. fill, stroke, stroke-width, fill-opacity: 0.5;
  4. outline, box-shadow

clickSelected(className = `selected-svg`) {
// update select element
const color = this.reverseColor();
this.poly.setAttribute("fill", color);
// this.poly.setAttribute("fill", "#67c23a");
const cssClass = this.poly.getAttribute("class");
// this.poly.setAttribute("class", "selected-svg");
this.poly.setAttribute("class", `${cssClass} ${className}`);
const style = "fill:lime; fill-opacity: 0.5; stroke:purple; stroke-width:10;";
this.poly.setAttribute("style", style);
}
reverseColor() {
const color = this.poly.getAttribute("fill");
return `#` + color.slice(1).split("").reverse().join("");
}


demo polygon

 ​

svg & stroke & style & class_stroke

<!DOCTYPE html>
<html>
<body>

<svg height="210" width="500">
<polygon points="200,10 250,190 160,210" style="fill:lime; stroke:purple; stroke-width:5" />
Sorry, your browser does not support inline SVG.
</svg>

</body>
</html>

style="fill:lime; stroke:purple; stroke-width:5" 


style

stroke-width, stroke

svg & stroke & style & class_CSS_02

<polygon fill="#cccccc" fill-opacity="1" points="249.5 0.5 674.5 0.5 674.5 136.5 249.5 136.5" class="feature selected-class" stroke="#00ff00" style="fill:lime; stroke:purple; stroke-width:5"></polygon>


css class

svg & stroke & style & class_stroke_03

stroke-width, stroke

.selected-class {
fill: #ccc !important;
stroke-width: 10px !important;
stroke: #0f0 !important;
}


size not change

svg & stroke & style & class_stroke_04


poly = document.querySelector(`polygon`);
// <polygon fill="#cccccc" fill-opacity="1" points="249.5 0.5 674.5 0.5 674.5 136.5 249.5 136.5" class="feature selected-class" stroke="#00ff00" style="fill:lime; stroke:purple; stroke-width:5"></polygon>
poly.getBBox();
// SVGRect {x: 249.5, y: 0.5, width: 425, height: 136}
poly.getBoundingClientRect();
// DOMRect {x: 174.64999389648438, y: 190.35000610351562, width: 297.5, height: 95.19998168945312, top: 190.35000610351562, …}

poly = document.querySelector(`polygon`);
// <polygon fill="#cccccc" fill-opacity="1" points="249.5 0.5 674.5 0.5 674.5 136.5 249.5 136.5" class="feature selected-class" stroke="#00ff00"></polygon>
poly.getBBox();
// SVGRect {x: 249.5, y: 0.5, width: 425, height: 136}
poly.getBoundingClientRect();
// DOMRect {x: 174.64999389648438, y: 190.35000610351562, width: 297.5, height: 95.19998168945312, top: 190.35000610351562, …}






xgqfrms