项目
在 GitHub 查看 charming
yuanqing/charming
关于
:tophat: 使用原生 JavaScript 的 Lettering.js
设计与媒体实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- -1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文charming

Lettering.js in vanilla JavaScript
- Supports changing the tag name or class name of the inserted DOM elements
- Supports controlling how the contents of the element are wrapped
Usage
HTML:
<h1>foo</h1>
JavaScript:
const charming = require('charming')
const element = document.querySelector('h1')
charming(element)
Boom:
<h1 aria-label="foo">
<span class="char1" aria-hidden="true">f</span>
<span class="char2" aria-hidden="true">o</span>
<span class="char3" aria-hidden="true">o</span>
</h1>
- Charming also works when the given element contains other (possibly nested) DOM elements; any character that is inside a text node in the given element will be wrapped.
- For accessibility, Charming adds an
aria-labelattribute on the given element andaria-hiddenattributes on each of the inserted DOM elements.
API
const charming = require('charming')
charming(element [, options])
elementis a DOM elementoptionsis an optional configuration object
Use options.tagName to change the tag name of the wrapper element:
charming(element, {
tagName: 'b'
})
Use options.setClassName to change the class name on each wrapper element:
charming(element, {
setClassName: function (index, letter) {
return `index-${index} letter-${letter}`
}
})
Use options.split to control how the contents of the element are wrapped:
charming(element, {
split: function (string) {
return string.split(/(\s+)/)
},
setClassName: function (index) {
return `word-${index}`
}
})
Installation
$ yarn add charming
License
探索相关项目
加载中…