This repository provides two themable and customizable CSS classes that can add dynamic lighting to your web page. Try out the demo!
light-effectis applied to any element you want casting a shadow. It will use css variables you define to calculate the proper directly and size for the shadow given your element's position relative to the light source.light-sourceis applied to the container and will add a gradient based layer to lighten content close to the source and dark content that is further. Note it's not needed forlight-effectto work and serves to double down on the luminosity effect.
- Copy luminosity.css into your project.
- Modify it if you need to, otherwise apply its classes
.light-effectand.light-sourceas needed.
- Modify it if you need to, otherwise apply its classes
- Supply required CSS variables if you don't want default.
- This is particularly important for element position
--lc-xand--lc-y. - See luminosity.css for a description of each variable.
- This is particularly important for element position
- Take a look at the demo for a working example to get started.
You can control the colors of both the ambient light source and the element shadows to fine tune to your site's pallet:
--lc-light-onand--lc-light-offcan be used to customize the color of the filter applied at both ends of the.light-effectcontainer gradient.- Use color
opacityto control the intensity of the ambient light filter. - Combine custom colors with
--lc-light-zand--lc-light-mto tighten or loosen the beam of light. - Remember:
.light-effectis not needed for directional shadows to work.
- Use color
--lc-shadow-colorcan be used to define the color of the shadows cast by the elements with.light-effect. You can pass a custom value to adapt to a given pallet your site is working with and control theopacity.
You can control the position of the ambient light source as well as attributes to customize the tightness of the beam and the elongation factor of shadows:
- The ambient source light's position can be modified in 4 ways:
--lc-light-xand--lc-light-ycan be used to set the 2d coordinates of the center of the light in%. These values can be negative or otherwise outside the bounds of the container to give the light a faraway effect.--lc-light-zsimulates the height of the light source and indirectly the spread of the beam and blurriness of element shadows. It's best kept positive.--lc-light-mis a measure of the extent of the light source's filters (both light and dark). It affects the range of the effect in the.light-sourcegradient but not the shadows of the elements.
--lc-xand--lc-ymust be used on elements for directional shadows to work and should be expressed in % and correspond to the center of the element. They can be set at runtime by javascript for elements that are naturally positioned.--lc-shadow-sensitivitydetermines the number ofpxthe shadow is offset by for each%distance the element is from the light source. By default it's set at0.05px.
