TL;博士
使用创建symbol-svg-sprite
并插入其片段svg+use
后,我想css-variables
在 #ShadowDOM 中使用 SVGpresentation attributes
来更改例如stroke-width="0"
,stroke-width="5"
并且transition property
必须工作,问题是这些stroke-width
值在任何情况下都有效(:悬停:活动:焦点)并且transition
不工作。
外部 SVG 示例
<svg style='display:none;' xmlns="http://www.w3.org/2000/svg">
<symbol id='symbol-id' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 20">
<path style='transition-duration: var(--custom-duration); transition-property: var(--custom-property);' stroke="var(--custom-stroke)" stroke-width="var(--custom-stroke-width)" fill="cyan" d="long..."
</symbol>
</svg>
插入 SVG+USE
<svg>
<use class="use-class" xlink:href="../transition-error.svg#symbol-id"></use>
</svg>
应用 CSS 样式
svg
outline 1px solid black
width 250px
height 250px
.use-class
--custom-stroke-width 0
--custom-duration .5s
--custom-property all
.use-class:hover
--custom-stroke-width 2
--custom-stroke blue
--custom-duration 2500ms
--custom-property all
预期行为
当您将鼠标悬停在 svg 容器上时,变量的值会发生变化,并且笔划会stroke-width 0
平滑地流入stroke-width 2
- 这种情况会发生但没有 分配给它,transition
但可以在
DevTools中看到transition
<path>
这在哪里工作?
- 通过标签内联 svg
<svg>
—<svg> <path d="..."> </svg>
<object></object>
使用带有外部 css 的标签
演示可以在 CodePen 上看到
如何使CSS transition
工作external-svg-sprites
?我厌倦了与此作斗争:(