Skip to content

vikasbhalla05/CSS-Variables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Changing CSS variables using JS dynamically

Project learnings

  • css variable declaration in :root
  • variable syntax --var_name
  • accessing variables inside css using var(--var_name)
  • capturing input value using querySelectorAll and adding MULTIPLE event listener for 2 events on the element
['change','mousemove'].forEach(evt => inputs.addEventListener(evt, handleUpdate));
  • passing in the function for the event listener
  • adding suffix like 'px' for the data-values using the dataset object in elements
  • getting and setting of the css variable using
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);

About

Changing CSS values dynamically using JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published