Reputation: 53245
I'm trying to create clip path around user's mouse. This is my code:
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;
This is the clip path I am trying to assign:
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%);
This is the error, totally unhelpful:
Error in parsing value for ‘clip-path’. Declaration dropped.
I really wonder why have CSS errors been always so unhelpful.
Anyway, does anyone see what's wrong with the clip path?
Upvotes: 0
Views: 413
Reputation: 954
The rule should not be ended with semicolon
el.style.clipPath = "polygon(...)"; // OK
el.style.clipPath = "polygon(...);"; // Fail
Upvotes: 1