Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

✨ Ever wanted to have reactive css variables in svelte? What if I told you there's a way?

License

NotificationsYou must be signed in to change notification settings

kaisermann/svelte-css-vars

Repository files navigation

Ever wanted to have reactive css variables in svelte? What if I told you there's a way?

svelte-css-vars exposes asvelte action which receives an object of properties that should be treated as css custom properties. By defining this object inside a$:{} reactive block,svelte-css-vars can update those css properties on the fly whenever some of its values change.

Usage

import cssVars from 'svelte-css-vars';

After importing the module, just define the reactive object of your custom properties:

letsome_state_variable=true;$:styleVars={titleColor:some_state_variable ?'red' :'blue',};

And then use the action, passing the object, on the desired element:

<style>div {color:var(--titleColor);  }</style><divuse:cssVars="{styleVars}"><!-- anything here will have access to var(--titleColor) --></div>

Example

repl

REPL

About

✨ Ever wanted to have reactive css variables in svelte? What if I told you there's a way?

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp