渐变
制作中的渐变:色标排列在色条上,当前色标在颜色选择器中编辑,另有渐变类型、角度和中心点。
本页内容
渐变编辑器用于制作渐变:色标排列在色条上,当前选中的色标在颜色选择器中编辑,此外还能设置渐变的类型、角度和中心点。其中每个控件都来自组件库本身:颜色选择器;用于设置色标位置的滑块和数字输入框;用于选择类型的分段控件;用于设置角度的旋钮;以及用于设置中心点的数字输入框。渐变组件自己补充的只有色标条、预览,以及让这一切保持同步的 gradient 行为脚本。
渐变
<div class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1"> <div class="gradient-preview" aria-hidden="true"></div> <div class="gradient-bar"></div> <div class="flex flex-wrap items-center gap-xs"> <button type="button" class="btn btn-sm gradient-add"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg>Add a stop </button> <button type="button" class="btn btn-sm gradient-remove"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /> </svg>Remove </button> <button type="button" class="btn btn-sm btn-quiet gradient-reverse"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M8 1.6667L8 14.3333" /><path d="M5.6667 6.3298L5.6667 11.45A0.55 0.55 0 0 1 5.1167 12L2.5566 12A0.55 0.55 0 0 1 2.0647 11.204L4.6248 6.0839A0.55 0.55 0 0 1 5.6667 6.3298Z" /><path d="M10.3333 6.3298L10.3333 11.45A0.55 0.55 0 0 0 10.8833 12L13.4434 12A0.55 0.55 0 0 0 13.9353 11.204L11.3752 6.0839A0.55 0.55 0 0 0 10.3333 6.3298Z" /> </svg>Reverse </button> </div> <div class="gradient-fields"> <fieldset class="gradient-color"> <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend> <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50"> <div class="color-picker-area"> <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div> </div> <span class="swatch swatch-lg color-picker-swatch"></span> <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue"> <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity"> <div class="color-picker-fields"> <select class="select select-sm color-picker-format" aria-label="Format"> <option value="hex" selected>Hex</option> <option value="rgb">RGB</option> <option value="oklch">OKLCH</option> </select> <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off"> </div> </div> </fieldset> <div class="flex flex-col gap-md min-w(0)"> <fieldset class="gradient-offset"> <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend> <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop"> <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent"> </fieldset> <fieldset class="gradient-type"> <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend> <div class="segmented segmented-sm" role="radiogroup" aria-label="Type"> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic </label> </div> </fieldset> <div class="flex flex-wrap items-start gap-lg"> <fieldset class="gradient-angle"> <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend> <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135"> <span class="dial-value">135°</span> <span class="dial-thumb"></span> </div> </fieldset> <fieldset class="gradient-center"> <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent"> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent"> </fieldset> </div> </div> </div> <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [ { id: 'dawn', offset: 0, color: '#ff6a00' }, { id: 'noon', offset: 55, color: '#ee0979' }, { id: 'dusk', offset: 100, color: '#4f46e5' }] } })})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach, gradient } from '@master/ui/behaviors'import PlusIcon from '@master/icons-react/native/16/soft/plus'import MinusIcon from '@master/icons-react/native/16/soft/minus'import FlipHorizontalIcon from '@master/icons-react/native/16/soft/flip-horizontal'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => { const detach = [ attach(root.current!), gradient(document.getElementById('sunrise')!, { value: { type: 'linear', angle: 135, center: [50, 50], stops: [ { id: 'dawn', offset: 0, color: '#ff6a00' }, { id: 'noon', offset: 55, color: '#ee0979' }, { id: 'dusk', offset: 100, color: '#4f46e5' } ] } }), ] return () => detach.forEach(stop => stop()) }, []) return ( <div ref={root} className="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style={{ '--gradient-ratio': '3 / 1' } as React.CSSProperties}> <div className="gradient-preview" aria-hidden="true"></div> <div className="gradient-bar"></div> <div className="flex flex-wrap items-center gap-xs"> <button type="button" className="btn btn-sm gradient-add"> <PlusIcon className="icon" />Add a stop </button> <button type="button" className="btn btn-sm gradient-remove"> <MinusIcon className="icon" />Remove </button> <button type="button" className="btn btn-sm btn-quiet gradient-reverse"> <FlipHorizontalIcon className="icon" />Reverse </button> </div> <div className="gradient-fields"> <fieldset className="gradient-color"> <legend className="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend> <div className="color-picker" style={{ '--color-picker-lightness': '.7', '--color-picker-chroma': '.19', '--color-picker-hue': '50' } as React.CSSProperties}> <div className="color-picker-area"> <div className="color-picker-thumb" role="slider" tabIndex={0} aria-label="Lightness and chroma" aria-valuemin={0} aria-valuemax={100} aria-valuenow={70}></div> </div> <span className="swatch swatch-lg color-picker-swatch"></span> <input type="range" className="slider color-picker-hue" min="0" max="360" defaultValue="50" aria-label="Hue" /> <input type="range" className="slider color-picker-alpha" min="0" max="100" defaultValue="100" aria-label="Opacity" /> <div className="color-picker-fields"> <select className="select select-sm color-picker-format" aria-label="Format" defaultValue="hex"> <option value="hex">Hex</option> <option value="rgb">RGB</option> <option value="oklch">OKLCH</option> </select> <input className="input input-sm color-picker-text" defaultValue="#ff6a00" aria-label="Color" spellCheck="false" autoComplete="off" /> </div> </div> </fieldset> <div className="flex flex-col gap-md min-w(0)"> <fieldset className="gradient-offset"> <legend className="mb(6) text-xs font-medium fg-text-muted">Position</legend> <input type="range" className="slider" min="0" max="100" step="1" defaultValue="0" aria-label="Position of the stop" /> <input type="number" className="input input-sm w(72)" min="0" max="100" step="1" defaultValue="0" aria-label="Position of the stop, in percent" /> </fieldset> <fieldset className="gradient-type"> <legend className="mb(6) text-xs font-medium fg-text-muted">Type</legend> <div className="segmented segmented-sm" role="radiogroup" aria-label="Type"> <label className="segmented-item"> <input type="radio" className="segmented-input" name="sunrise-type" value="linear" defaultChecked />Linear </label> <label className="segmented-item"> <input type="radio" className="segmented-input" name="sunrise-type" value="radial" />Radial </label> <label className="segmented-item"> <input type="radio" className="segmented-input" name="sunrise-type" value="conic" />Conic </label> </div> </fieldset> <div className="flex flex-wrap items-start gap-lg"> <fieldset className="gradient-angle"> <legend className="mb(6) text-xs font-medium fg-text-muted">Angle</legend> <div className="dial dial-sm dial-full" role="slider" tabIndex={0} aria-label="Angle" aria-valuenow={135} aria-valuemin={0} aria-valuemax={360} aria-valuetext="135°" style={{ '--dial-value': '135' } as React.CSSProperties}> <span className="dial-value">135°</span> <span className="dial-thumb"></span> </div> </fieldset> <fieldset className="gradient-center"> <legend className="mb(6) text-xs font-medium fg-text-muted">Center</legend> <input type="number" className="input input-sm w(72)" min="0" max="100" defaultValue="50" aria-label="Center across, in percent" /> <input type="number" className="input input-sm w(72)" min="0" max="100" defaultValue="50" aria-label="Center down, in percent" /> </fieldset> </div> </div> </div> <pre className="code-block gradient-css" role="region" tabIndex={0} aria-label="The gradient as CSS">{``}</pre> </div> )}<script> import { attach, gradient } from '@master/ui/behaviors' import PlusIcon from '@master/icons-svelte/native/16/soft/plus' import MinusIcon from '@master/icons-svelte/native/16/soft/minus' import FlipHorizontalIcon from '@master/icons-svelte/native/16/soft/flip-horizontal' function mounted(root) { const detach = [ attach(root), gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [ { id: 'dawn', offset: 0, color: '#ff6a00' }, { id: 'noon', offset: 55, color: '#ee0979' }, { id: 'dusk', offset: 100, color: '#4f46e5' } ] } }), ] return () => detach.forEach(stop => stop()) }</script><div class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1" {@attach mounted}> <div class="gradient-preview" aria-hidden="true"></div> <div class="gradient-bar"></div> <div class="flex flex-wrap items-center gap-xs"> <button type="button" class="btn btn-sm gradient-add"> <PlusIcon class="icon" />Add a stop </button> <button type="button" class="btn btn-sm gradient-remove"> <MinusIcon class="icon" />Remove </button> <button type="button" class="btn btn-sm btn-quiet gradient-reverse"> <FlipHorizontalIcon class="icon" />Reverse </button> </div> <div class="gradient-fields"> <fieldset class="gradient-color"> <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend> <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50"> <div class="color-picker-area"> <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div> </div> <span class="swatch swatch-lg color-picker-swatch"></span> <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue"> <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity"> <div class="color-picker-fields"> <select class="select select-sm color-picker-format" aria-label="Format"> <option value="hex" selected>Hex</option> <option value="rgb">RGB</option> <option value="oklch">OKLCH</option> </select> <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off"> </div> </div> </fieldset> <div class="flex flex-col gap-md min-w(0)"> <fieldset class="gradient-offset"> <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend> <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop"> <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent"> </fieldset> <fieldset class="gradient-type"> <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend> <div class="segmented segmented-sm" role="radiogroup" aria-label="Type"> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic </label> </div> </fieldset> <div class="flex flex-wrap items-start gap-lg"> <fieldset class="gradient-angle"> <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend> <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135"> <span class="dial-value">135°</span> <span class="dial-thumb"></span> </div> </fieldset> <fieldset class="gradient-center"> <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent"> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent"> </fieldset> </div> </div> </div> <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, gradient } from '@master/ui/behaviors'import PlusIcon from '@master/icons-vue/native/16/soft/plus'import MinusIcon from '@master/icons-vue/native/16/soft/minus'import FlipHorizontalIcon from '@master/icons-vue/native/16/soft/flip-horizontal'const root = ref(null)let detach = []onMounted(() => { detach = [ attach(root.value), gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [ { id: 'dawn', offset: 0, color: '#ff6a00' }, { id: 'noon', offset: 55, color: '#ee0979' }, { id: 'dusk', offset: 100, color: '#4f46e5' } ] } }), ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template> <div ref="root" class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1"> <div class="gradient-preview" aria-hidden="true"></div> <div class="gradient-bar"></div> <div class="flex flex-wrap items-center gap-xs"> <button type="button" class="btn btn-sm gradient-add"> <PlusIcon class="icon" />Add a stop </button> <button type="button" class="btn btn-sm gradient-remove"> <MinusIcon class="icon" />Remove </button> <button type="button" class="btn btn-sm btn-quiet gradient-reverse"> <FlipHorizontalIcon class="icon" />Reverse </button> </div> <div class="gradient-fields"> <fieldset class="gradient-color"> <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend> <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50"> <div class="color-picker-area"> <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div> </div> <span class="swatch swatch-lg color-picker-swatch"></span> <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue"> <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity"> <div class="color-picker-fields"> <select class="select select-sm color-picker-format" aria-label="Format"> <option value="hex" selected>Hex</option> <option value="rgb">RGB</option> <option value="oklch">OKLCH</option> </select> <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off"> </div> </div> </fieldset> <div class="flex flex-col gap-md min-w(0)"> <fieldset class="gradient-offset"> <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend> <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop"> <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent"> </fieldset> <fieldset class="gradient-type"> <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend> <div class="segmented segmented-sm" role="radiogroup" aria-label="Type"> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial </label> <label class="segmented-item"> <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic </label> </div> </fieldset> <div class="flex flex-wrap items-start gap-lg"> <fieldset class="gradient-angle"> <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend> <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135"> <span class="dial-value">135°</span> <span class="dial-thumb"></span> </div> </fieldset> <fieldset class="gradient-center"> <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent"> <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent"> </fieldset> </div> </div> </div> <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre> </div></template>#值
渐变是一个由四部分组成的值:
| 部分 | 含义 |
|---|---|
type | linear、radial 或 conic |
angle | 角度(度),用于线性渐变和锥形渐变 |
center | 两个百分比,用于径向渐变和锥形渐变 |
stops | 每个色标都有一个始终跟随它的 id、取值 0 到 100 的 offset,以及一个 color |
颜色的写法与颜色选择器一致:以十六进制表示的 sRGB,并带有不透明度。gradientCss(value) 将渐变输出为 CSS,预览和复制的文本都来自它:在能够指定插值空间的浏览器中使用 OKLab 插值,并在此之前先提供一行回退声明,供不支持的浏览器使用。
background-image: linear-gradient(90deg, #ff6a00 0%, #ee0979 100%);background-image: linear-gradient(in oklab 90deg, #ff6a00 0%, #ee0979 100%);编辑器不会回读 CSS:编辑器持有的是值,应用程序保存的也是值,而不是文本。
#色标
- 色标的手柄是一个滑块,控制色标的位置,在色条上显示为一个带有该色标颜色的圆片。按下手柄即选中该色标,拖动即可移动;方向键每次移动 1,按住 Shift 再按方向键,每次移动 10,Home 和 End 将它移到两端。当前选中的色标带有
aria-current="true",会稍稍向前突出并显示一道墨色圆环。 - 色标可以交叉。 一个色标移过另一个色标时,仍保留自己的 id,其手柄也保持焦点;渐变按各色标位置的先后顺序绘制。两个色标位于同一位置时会形成硬边,并保持原有顺序。
- 添加会在当前色标之后 10 个单位处放置一个与其同色的新色标,最远到 100。删除(使用按钮或 Delete 键)会把焦点交给色条上的下一个色标,没有下一个时交给前一个。色标至少要有两个:只剩两个时,无法再删除色标。
- 反转会把色标颠倒过来:每个位置变为 100 减去原值。
拖动绝不是唯一的操作方式:位置旁边另有滑块和数字输入框,每个色标也都能用 Tab 键到达。
#状态
在根元素上设置 aria-readonly="true" 表示渐变不可更改,设置 aria-disabled="true" 表示渐变未启用:两种情况下手柄都保持原位,控件都被禁用。
#行为脚本
import { gradient, gradientCss } from '@master/ui/behaviors/gradient.js'const editor = gradient(document.querySelector('.gradient'), { value: { type: 'linear', angle: 90, center: [50, 50], stops: [ { id: 'from', offset: 0, color: '#ff6a00' }, { id: 'to', offset: 100, color: '#ee0979' }, ] },})editor.value // the value as abovegradientCss(editor.value).text // the two lines to copy读者操作过程中会持续派发 input 事件,操作结束时派发 change 事件;通过代码设置 value 会显示另一个渐变,但不派发任何事件。行为脚本根据值生成手柄标记,因此自行生成手柄标记的框架应传入 draw。它在根元素上以 --gradient 和 --gradient-fallback 发布整个渐变,并在每个色标的手柄上以 --gradient-offset 和 --gradient-color 发布该色标:编辑器所绘制的是它的内容,而由样式表负责摆放。
#键盘操作
| 按键 | 操作 |
|---|---|
| Tab | 移到色条上的当前色标,然后依次经过各控件;其他色标可用指针选中,或通过它们在色条 Tab 顺序中的位置到达 |
| ArrowRight, ArrowUp | 在色标上:向终点移动 1 个点;按住 Shift 时移动 10 个点。在从右到左排版的页面中,ArrowRight 向左移动 |
| ArrowLeft, ArrowDown | 在色标上:向起点移动 1 个点;按住 Shift 时移动 10 个点 |
| PageUp, PageDown | 在色标上:移动 10 个点 |
| Home, End | 在色标上:移到 0 或 100 |
| Delete, Backspace | 在色标上:色标多于两个时将其移除,并把焦点交给相邻色标 |
#无障碍
- 每个手柄都以它在色标中的序位命名,并通过
aria-valuetext说明其位置和颜色。 - 预览只是值的图像:请对辅助技术隐藏它,因为色标和 CSS 已经表达了相同的信息。
- 在强制颜色模式下,渐变保留自身的颜色,因为这些颜色就是它的内容;手柄和色条则用系统颜色描边。
#React、Svelte 和 Vue
gradient 组件根据值生成手柄和控件的标记,并接入行为脚本。用 npx master-ui add gradient 将组件复制到项目中。React、Svelte 和 Vue 介绍了这些组件的实现和用法。
#类名
| 类名 | 说明 |
|---|---|
gradient | 编辑器:预览、色标条和各控件。gradient 行为脚本写入色标的手柄并发布渐变。在其上设置 aria-readonly="true" 或 aria-disabled="true" 可防止更改 |
gradient-preview | 棋盘格上的渐变,比例为 16 : 9,可用 --gradient-ratio 另行设置;用 aria-hidden 隐藏它,因为色标和 CSS 已表达相同的内容 |
gradient-bar | 无论哪种类型,都按从起点到终点排列色标,呈现为供手柄放置的短凹槽 |
gradient-stop | 色标的手柄,由行为脚本写入:珍珠色圆环中填充该色标颜色的圆盘,位于色条上 --gradient-offset 处;它是表示偏移量的滑块,名称说明它在色标中的位置 |
gradient-fields | 各控件排成一列,空间足够时两两并排 |
gradient-color | 容纳当前色标的 color-picker;由 gradient 行为脚本附加该选择器 |
gradient-offset | 容纳一个滑块和一个数字输入框,取值 0 到 100,用于设置当前色标的偏移量 |
gradient-type | 容纳选择类型的单选按钮:linear、radial 和 conic;一个分段控件 |
gradient-angle | 容纳角度旋钮,取值 0 到 360 度,用于线性和锥形渐变 |
gradient-center | 容纳两个数字输入框,即中心的 x 和 y 百分比,用于径向和锥形渐变 |
gradient-add | 在当前色标之后 10 个点处添加一个当前颜色的色标,最多到 100 |
gradient-remove | 移除当前色标;只剩两个色标时禁用 |
gradient-reverse | 反转色标顺序 |
gradient-css | 可复制的 CSS 渐变,由行为脚本写入:先是回退值,再是在 OKLab 中插值的写法 |
#自定义属性
| 属性 | 默认值 | 说明 |
|---|---|---|
--gradient | none | 在 OKLab 中插值的渐变,由行为脚本写入 |
--gradient-fallback | none | 在 sRGB 中插值的渐变,供无法指定插值方式的浏览器使用 |
--gradient-bar | 色条的填充:无论渐变类型如何,都将所有色标从起点到终点绘制为在 sRGB 中插值的线性渐变,由行为脚本写入在 gradient 上设置 | |
--gradient-ratio | 预览的形状;默认为 16 / 9在 gradient-preview 上设置 | |
--gradient-offset | 手柄在色条上的位置,取值 0 到 100,由行为脚本写入在 gradient-stop 上设置 | |
--gradient-color | 手柄所属色标的颜色,由行为脚本写入在 gradient-stop 上设置 |
#相关内容
- 颜色选择器可选择任意颜色:在明度与色度平面上选取,调整色相和不透明度,或直接输入。
- 旋钮绕圆周转动滑钮来设置数值,例如以旋钮方式调节的强度、角度或方向。
- 滑块原生范围输入控件,细窄的凹槽中有一个带珍珠质感的滑钮。
- 分段控件多个选项共用一个凹槽,凸起面板滑向当前选项。
- 色样带细边线的圆形色样,用于查看或选择颜色。