admin管理员组文章数量:1392007
In my case, I would like to apply animations on hover but to simplify the CSS I wanted to apply a class with the animations on hover instead of writing new CSS with :hover.
In my case, I would like to apply animations on hover but to simplify the CSS I wanted to apply a class with the animations on hover instead of writing new CSS with :hover.
Share Improve this question edited Apr 22, 2023 at 11:13 Eli O. asked Apr 19, 2023 at 21:50 Eli O.Eli O. 2,1273 gold badges28 silver badges35 bronze badges 1- What about creating a "helper" CSS class in the svelte file and toggle that class based on your reactive variable? This way, the "hover:" part moves into the helper class. – Florian Commented Jun 4, 2024 at 16:21
1 Answer
Reset to default 6A solution I found was to bine a variable and functions on hover to dynamically apply the class
<script>
let isHovered = false;
</script>
<div class:class-on-hover={isHovered} on:mouseover={() => isHovered = true} on:mouseout={() => isHovered = false}>
Hover me!
</div>
<style>
.class-on-hover {
color: red;
}
</style>
本文标签: javascriptIn sveltehow to apply a class on hover without the CSS hoverStack Overflow
版权声明:本文标题:javascript - In Svelte, how to apply a class on hover without the CSS :hover? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744774254a2624530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论