svg & stroke & style & class
svg & stroke & style & class
svg selected style
methods
-
style
-
class, !important
-
fill, stroke, stroke-width, fill-opacity: 0.5;
-
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
https://www.w3schools.com/graphics/tryit.asp?filename=trysvg_polygon
<!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
<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
stroke-width, stroke
.selected-class {
fill: #ccc !important;
stroke-width: 10px !important;
stroke: #0f0 !important;
}
size not change
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,原文链接:https://www.cnblogs.com/xgqfrms/p/12303736.html
未经授权禁止转载,违者必究!
标签:
style
, polygon
, CSS
, stroke
, Class
, svg selected
, stroke === color
, stroke-width
, CSS3
, SVG
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2019-02-13 智能货柜 & 技术原理 (动态视觉识别 + 重力感应) All In One