解析“clip-path”的值时出错

Error in parsing value for ‘clip-path’

我正在尝试围绕用户的鼠标创建剪辑路径。这是我的代码:

const rect = this.image.getBoundingClientRect();
const width = rect.right - rect.left;
const height = rect.bottom - rect.top;

const clipSizePx = 10;
const clipSizePerc = 100 * (clipSizePx / Math.max(width, height));

const mouseXPerc = 100 * ((e.clientX - rect.left) / width);
const mouseXStartPerc = Math_cap(mouseXPerc - clipSizePerc / 2, 0, 100);
const mouseXEndPerc = Math_cap(clipSizePerc/2 + mouseXPerc, 0,100);

const mouseYPerc = 100 * ((e.clientY - rect.top) / height);
const mouseYStartPerc = Math_cap(mouseYPerc - clipSizePerc / 2, 0, 100);
const mouseYEndPerc = Math_cap(mouseYPerc + clipSizePerc / 2, 0, 100);
const clipPath = "clip-path: polygon(0% 0%, 0% 100%, "
    + mouseXStartPerc + "% 100%,"
    + mouseXStartPerc + "% " + mouseYStartPerc + "%,"
    + mouseXEndPerc + "% " + mouseYStartPerc + "%,"
    + mouseXEndPerc + "% " + mouseYEndPerc + "%,"
    + mouseXStartPerc + "% " + mouseYEndPerc + "%,"
    + mouseXStartPerc + "% 100%,"
    + " 100% 100%,"
    + " 100% 0%);";
console.log("Clip path: ", clipPath,"\nMouse: ", [mouseXPerc, mouseYPerc]);
this.image.style.clipPath = clipPath;

这是我要分配的剪辑路径:

clip-path: polygon(0% 0%, 0% 100%, 30.90039334549982% 100%,30.90039334549982% 58.02269121483121%,32.229061634508525% 58.02269121483121%,32.229061634508525% 59.351359503839916%,30.90039334549982% 59.351359503839916%,30.90039334549982% 100%, 100% 100%, 100% 0%); 

这是错误,完全没有帮助:

Error in parsing value for ‘clip-path’. Declaration dropped.

我真的很奇怪为什么 CSS 错误总是那么无用。

无论如何,有人看到剪辑路径有什么问题吗?

规则不应以分号结尾

el.style.clipPath = "polygon(...)";   // OK
el.style.clipPath = "polygon(...);";  // Fail