sdxc

[ @sdxc/u/effects ]

backdropOpacity

Fades what shows through the element's translucent background, taking CSS's native 0–1 range or a percentage string.

import { backdropOpacity } from "@sdxc/u/effects";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.backdropOpacity()css({ "--ui-backdrop-opacity": "0.5", backdropFilter: "... opacity(var(--ui-backdrop-opacity, 1)) ...", WebkitBackdropFilter: "... opacity(var(--ui-backdrop-opacity, 1)) ..." })
u.transparencySafe(u.backdropOpacity("25%"))css({ "@media (prefers-reduced-transparency: no-preference)": { "--ui-backdrop-opacity": "25%", backdropFilter: "...", WebkitBackdropFilter: "..." } })

Examples

Basic example

Use backdropOpacity(n) with another backdrop filter to set how strongly the filtered backdrop shows, from 0 to 1:

backdropOpacity(0.25)
backdropOpacity(0.5)
backdropOpacity(0.75)
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[backdropInvert(), backdropOpacity(0.25), ...]}>
			backdropOpacity(0.25)
		</div>
	</div>
	<div mix={[...]}>
		<div mix={[backdropInvert(), backdropOpacity(0.5), ...]}>backdropOpacity(0.5)</div>
	</div>
	<div mix={[...]}>
		<div mix={[backdropInvert(), backdropOpacity(0.75), ...]}>
			backdropOpacity(0.75)
		</div>
	</div>
</div>

Applying on a state

Wrap the call in a state utility to scope it to one selector.

u.hover(u.backdropOpacity())

Responsive design

Wrap the call in a container query to scope it to one width.

u.at("md", u.backdropOpacity())

Signature

u.backdropOpacity(value?: number | (string & {}))

Written by Sergio Xalambrí. Follow @sergiodxa for new packages, or sponsor the work.