window.addEventListener("mouseup", (e) => {
// 在 #000000 和 #FFFFFF 之间随机选取一个颜色
const color = Math.round(Math.random() * 0xffffff);
// 将 color 变量的值按照 CSS 的要求进行格式化
const fill = "#" + color.toString(16).padStart(6, "0");
// 将 color 变量设置的颜色应用到实际点击的元素上
e.target.style.fill = fill;
作为一个展示属性,他可以被很多元素使用,但和它紧密相关的只有下面的 23 个元素:<a>
, <circle>
, <clipPath>
, <defs>
, <ellipse>
, <foreignObject>
, <g>
, <image>
, <line>
, <marker>
, <mask>
, <path>
, <pattern>
, <polygon>
, <polyline>
, <rect>
, <svg>
, <switch>
, <symbol>
, <text>
, <textPath>
, <tspan>
, <use>
bounding-box
| visiblePainted
| visibleFill
| visibleStroke
| visible
| painted
| fill
| stroke
| all
| none