프로젝트
GitHub에서 보기 charming
yuanqing/charming
소개
:tophat: 바닐라 JavaScript로 만든 Lettering.js
디자인 및 미디어측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalcharming

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
관련 프로젝트 살펴보기
불러오는 중…