如何使CSS过渡与JS .AppendChild函数一起使用?
通过mouseenter
事件,我正在将js函数施加到svg路径元素
:
const fadeIn = (event, locale) => {
event.target.style.fill = 'hwb(' + (120 - score[locale] * 1.2) + ' 0% 0% / 1)'
}
这与css:
transition: fill .25s;
问题的 transition
一起工作。 stroke
在SVG路径之间重叠
,以及将悬停元素的笔触带到前面所有其他所有方面的唯一方法是将其添加到JS函数:
event.target.parentElement.appendChild(event.target)
不幸的是,这无效正确使用过渡
。改用类不是一个选项,因为我需要分数
和locale
hwb()
color Style属性属性。
我有什么可以做的,以确保元素位于正面并使过渡起作用?
Via mouseenter
event I'm applying following JS function to an svg path element
:
const fadeIn = (event, locale) => {
event.target.style.fill = 'hwb(' + (120 - score[locale] * 1.2) + ' 0% 0% / 1)'
}
This works together with a transition
from CSS:
transition: fill .25s;
Problem is that the stroke
overlaps between svg paths
, and the only way to bring the hovered element's stroke to the front above all others is by adding to the JS function:
event.target.parentElement.appendChild(event.target)
Unfortunately this doesn't work properly with the transition
. Applying a class instead is not an option because I need score
and locale
parameters inside the hwb()
color style property.
Is there anything I can do, to ensure the element being at the front AND making the transition work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用JavaScript自己插入颜色。
一种简单的方法可能是为每个可能的分数创建一个类。看起来您的分数在0到100之间。因此,您只需要定义101个类。例如。像:
One way would be to interpolate the colour yourself using Javascript.
A simpler approach might be to create a class for each possible score. It looks like your scores are between 0 and 100. So you'd only need 101 classes defined. Eg. something like: