如何在Safari中隐藏CSS的offset-path属性?CSS支持的规则不起作用。

huangapple go评论62阅读模式
英文:

How to hide css offset-path property in safari? CSS supports rule doesn't work as expected

问题

CSS动画路径在Safari中不受支持。我尝试使用CSS支持规则来定位偏移路径,但它不起作用。

if (CSS.supports("offset-path", "M0.5 1H1549.5")) {
   console.log("支持");
   // 动画路径不受支持,应用备用样式或其他操作
   //   element.style.transform = "translateX(100px)";
} else {
   console.log("不支持");
}

我尝试了这个逻辑,但在Chromium浏览器中它不起作用。我做错了什么?

英文:

CSS motion path isn't supported in safari. I've tried using CSS supports rule to target offset-path but it isn't working.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

if (CSS.supports(&quot;offset-path&quot;, &quot;M0.5 1H1549.5&quot;)) {
   console.log(&quot;supported yay&quot;);
   // Motion path is not supported, apply fallback styles or alternative actions
   //   element.style.transform = &quot;translateX(100px)&quot;;
} else {
   console.log(&quot;not supported&quot;);
}

<!-- end snippet -->

I try this logic and it doesn't work in chromium browsers. What am I doing wrong?

答案1

得分: 1

CSS.supports()的第二个参数必须是一个有效的值。您是否忘记将您的值包装在 path 中了?

// 返回 false,该值不是有效的值
console.log(CSS.supports("offset-path", "M0.5 1H1549.5"));

// 在Chromium浏览器上返回 true
console.log(CSS.supports("offset-path", "path('M0.5 1H1549.5')"));
英文:

The second parameter for CSS.supports() has to be a valid value. Did you perhaps forget to wrap your value in path?

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

// Returns false, the value is not a valid value
console.log(CSS.supports(&quot;offset-path&quot;, &quot;M0.5 1H1549.5&quot;));

// Returns true on Chromium browsers
console.log(CSS.supports(&quot;offset-path&quot;, &quot;path(&#39;M0.5 1H1549.5&#39;)&quot;));

<!-- end snippet -->

答案2

得分: 1

Chromium浏览器支持使用path()值的offset-path属性。但是,CSS.supports()需要正确的值语法,否则它将返回false。没有中间选项,也就是说,没有结果会显示"它支持该值,但语法不正确"。所以,只需像这样使用正确的值:

if (CSS.supports("offset-path", `path("M0.5 1H1549.5")`)) {
...
英文:

Chromium browsers do support offset-path property with path() values.

But CSS.supports() requires the correct value syntax and otherwise, it'll return false. There's no in-between, i.e. a result that says "It supports the value but the syntax is incorrect".

So, just use the correct value like this:

if (CSS.supports(&quot;offset-path&quot;, `path(&quot;M0.5 1H1549.5&quot;)`)) {
...

huangapple
  • 本文由 发表于 2023年6月12日 17:12:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定