项目作者: noeldelgado

项目描述 :
:lollipop: Apply text gradients with CSS, inline SVG mask fallback or a solid color as last resort.
高级语言: JavaScript
项目地址: git://github.com/noeldelgado/text-gradient.git
创建时间: 2015-09-13T12:28:21Z
项目社区:https://github.com/noeldelgado/text-gradient

开源协议:MIT License

下载


text-gradient

npm-image

Vanilla js version of javierbyte’sreact-textgradient.

Apply text gradients with CSS, inline SVG mask fallback or a solid color as last resort.

Note: Not recommended for large amounts of text, most suitable for headings and the like.

Demo

text-gradient

Features

  • Uses CSS text gradients when possible (Chrome, Safari, iOS, android).
  • Fallbacks to SVG masking on Firefox url(#gradient).
  • The text remains controlled via CSS (font size, family, weight, text-align, line-height, etc…)

Install

  1. npm install text-gradient --save

Usage

  1. @argument element <required> [NodeElement] the element to apply the gradient
  2. @argument options <optional> [Object] Gradient color-stops, direction, text.
  1. const TextGradient = require('text-gradient');
  2. const gradient = new TextGradient(document.getElementById('headline'), {
  3. from: '#B0E537',
  4. to: '#009DE9',
  5. direction: 'right'
  6. });

Options

name type default description
text String element.textContent The text to display
from String (valid color format) transparent Gradient’s first color-stop
to String (valid color format) transparent Gradient’s last color-stop
direction String right One of (top, right, bottom, left)

API

updateText(String)

Changes the text contents.

  1. /*
  2. * @argument text <required> [String]
  3. * @return undefined
  4. */
  5. gradient.updateText('Some other catchy headline');

destroy()

Remove the text-gradient effect, references and elements created by the instance (svg container, defs, extra spans to wrap the content, etc).

  1. /*
  2. * @return null
  3. */
  4. gradient = gradient.destroy();

License

MIT © Noel Delgado