Skip to content

Build your personal knowledge base with Trilium Notes

1.7 KB
Raw Blame
/*
 * A custom property animates only once it is registered with a type, so both ends are registered
 * for the transition below. A percentage size is a share of the length of the gradient. Where
 * `@property` is unsupported the fades snap, and the `var()` fallbacks in the mask stand in for the
 * initial values.
 */
@property --scroll-fade-start {
    syntax: "<length-percentage>";
    inherits: false;
    initial-value: 0px;
}

@property --scroll-fade-end {
    syntax: "<length-percentage>";
    inherits: false;
    initial-value: 0px;
}

/*
 * Fades whichever edge a scroll container continues past, so what is cut off reads as going on
 * rather than as ending.
 *
 * A mask rather than a painted gradient: it holds over any background, including a semi-transparent
 * tint over a window material, which no painted color could match.
 */
.scroll-fade {
    mask-image: linear-gradient(
        var(--scroll-fade-direction, to bottom),
        transparent,
        black var(--scroll-fade-start, 0px),
        black calc(100% - var(--scroll-fade-end, 0px)),
        transparent
    );
    transition:
        --scroll-fade-start var(--scroll-fade-duration, 300ms) ease,
        --scroll-fade-end var(--scroll-fade-duration, 300ms) ease;
}

/* A gradient takes a physical direction, so the ends swap in a right-to-left container. */
.scroll-fade-horizontal {
    --scroll-fade-direction: to right;
}

.scroll-fade-horizontal.scroll-fade-rtl {
    --scroll-fade-direction: to left;
}

.scroll-fade-start {
    --scroll-fade-start: var(--scroll-fade-size, 20px);
}

.scroll-fade-end {
    --scroll-fade-end: var(--scroll-fade-size, 20px);
}

@media (prefers-reduced-motion: reduce) {
    .scroll-fade {
        transition: none;
    }
}