Ad
How Can I Add Transform To Unicode Letters
I am working on some text animation on my language. But separating the letters to spans using a js, results in something like follows:
<span class="letter" style="transform: translate(0.55em, 1.1em) scale(1.5);">ध</span>
<span class="letter" style="transform: translate(0.55em, 1.1em);">्</span>
<span class="letter" style="transform: translate(0.55em, 1.1em);">य</span>
<span class="letter" style="transform: translate(0.55em, 1.1em);">ो</span>
The Script I use is
textWrapper.innerHTML = textWrapper.textContent.replace(/\S/g, "<span class='letter'>$&</span>");
and results in html is as follows
The result should look like: ध्यो because those empty spaces get combined in unicode.
It only breaks when .letter
is applied with display:inline-block
which is required to apply transforms.
Is there a way I can achieve result of ध्यो and still apply transforms to each letter?
Ad
Answer
For that language you must separate them by words as separating by letters won't work. The following code should work.
let textEl = document.querySelector("p");
if (textEl) {
let words = textEl.textContent.split(" ");
let finalStr = words.reduce((accumulator, currentValue, currentIndex) => {
return currentIndex === 1 ?
`<span class='word'>${accumulator}</span> <span class='word'>${currentValue}</span>` :
`${accumulator} <span class='word'>${currentValue}</span>`
;
});
textEl.innerHTML = finalStr;
}
console.log(textEl.innerHTML);
<p>some text for testing</p>
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad