Git Product home page Git Product logo

split-html-to-chars's Introduction

Split html to letters for animation

Takes this:

<h2>Some <strong>bold</strong> text<br> with<i>Tags</i></h2>

Returns this:

<h2>
	<span class="letter">S</span>
	<span class="letter">o</span>
	<span class="letter">m</span>
	<span class="letter">e</span>
	<span class="letter"> </span>
	<strong>
		<span class="letter">b</span>
		<span class="letter">o</span>
		<span class="letter">l</span>
		<span class="letter">d</span>
	</strong>
	<span class="letter"> </span>
	<span class="letter">t</span>
	<span class="letter">e</span>
	<span class="letter">x</span>
	<span class="letter">t</span>
    <br>
	<span class="letter">w</span>
	<span class="letter">i</span>
	<span class="letter">t</span>
	<span class="letter">h</span>
	<i>
		<span class="letter">T</span>
		<span class="letter">a</span>
		<span class="letter">g</span>
		<span class="letter">s</span>
	</i>
</h2>

If invoked like this:

import Splitter from 'split-html-to-chars';

Splitter(html,'<span class="letter">$</span>');

Why i did that

For animations like this one:

Letters animation

Common use case might be replacing HTML on load:

import Splitter from 'split-html-to-chars';
// iterating each replaced element
let els = document.querySelectorAll(".js-splitme");
[].forEach.call(els, function(el) {
	// outerHTML, thats *important*, no direct text nodes should be in parsed HTML
	el.outerHTML = Splitter(el.outerHTML, '<span class="letter">$</span>');
});

Yuri akella Artiukh

split-html-to-chars's People

Contributors

akella avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.