npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

css-fade

v0.11.8

Published

Css mask based fade effects for html elements in css made convenient, in TailwindCSS, UnoCSS, and CSS.

Downloads

104

Readme

css-fade

Css mask based fade effects for html elements in css made convenient, in TailwindCSS, UnoCSS, and CSS.

css-fade fades out any part of html elements it's applied to, including all children using the css mask property.

Usage with TailwindCSS & UnoCSS

Directions & sizing

Usage with UnoCSS, and TailwindCSS are the same, the only difference is TailwindCSS values are strict while UnoCSS values aren't. TailwindCSS values are the same values you'll find on spacing properties.


<!-- Set fade towards a single direction -->
<div class="fade-b-24" ></div>

<!-- Set fade towards a 2 directions -->
<div class="fade-x-24" ></div>

<!-- Set fade towards all directions -->
<div class="fade-12" ></div>

<!-- Set fade towards multiple directions -->
<div class="fade-x-24 fade-y-12" ></div>
<div class="fade-t-12 fade-r-6" ></div>

<!-- Kitchen sink, yes multiple classes can be applied on one element -->
<div class="fade-tl-12 fade-b-4" ></div>

<!-- Using relative (%) values -->
<div class="fade-x-[30%]" ></div>

Fading between different values

Use fade-from-<0-100> and fade-to-<0-100> to set the opacity from which the fade starts from, and ends at. the from value is the center, the to value are the edges.


<div class="fade-b-24 fade-to-80"></div>

Installation Guides

  • TailwindCSS
  • UnoCSS
  • CSS

Installing The Unified Package

css-fade comes in a single unified package for all frameworks.


pnpm add css-fade
npm install css-fade
yarn install css-fade

TailwindCSS

After installing the unified css-fade package, add css-fade to your tailwind.config.*:

// tailwind.config.mjs

/** @type {import('tailwindcss').Config} */

// import pluginFade from 'css-fade/tailwindcss' // <=== you may also choose to import it

export default {
	plugins: [
		require('css-fade/tailwindcss') // <=== add using require
    // pluginFade // <===== or import it
	],
}

UnoCSS

After installing the unified css-fade package, add css-fade to your uno.config.*:

// uno.config.ts

import presetFade from "css-fade/unocss" // <=== import

import {
  defineConfig,
  presetWind,
} from "unocss"

export default defineConfig({
  presets: [
    presetWind(),
    presetFade() // <=== pass in as preset
  ],
})

CSS

You may use css-fade in CSS by importing the base CSS, or by copying over the core css.

Importing base CSS

After installing the unified css-fade package, import css-fade/css into your entry file.

// /src/main.ts
import 'css-fade/css' // <==== import base css

Copying CSS

You can find the base CSS for css-fade in /packages/core/src/css/index.css in this repository, copy and paste the CSS in a global context in your project.

Limitations

Even though you can fade on 2 dimensions (vertically & horizontally) it's not recommended to do so with this library in most cases as ugly lines may appear. Due to the way positioning & sizing works in css backgrounds which we're using to generate the mask templates dynamically we had to choose between two appraoches,

  • Approach 1: code named BurningPaper (find implementation in playground/astro-css/src/components/BurningPaper.astro ) This approach gives us smooth transitions between dimensions, and allows us to add extra utility classes for improved gradient smoothing but does not allow relative (%) values to be used.

  • Approach 2: code named RadicalRabbit (find implementation in playground/astro-css/src/components/RadicalRabbit.astro ) This approach is a little more janky with transitions between dimensions, and although improvements are possible, does not allow easy improvements to the gradient smoothing.

In vast majority of cases likely usage will be in one dimension, and being able to set a % based fade will be handy, so this package primarily uses Approach 2.

You can find comparison between the 2 approaches at playground/astro-css/src/pages/approaches.astro.