/**
* TEXT EFFECTS
* (needs splitting up a little)
*/
var textFx = {
init: function () {
// Find all elements with .text-fx
var elems = document.getElementsByClassName('text-fx');
for (var i = 0; i < elems.length; i++) {
// Wrap inner HTML characters with <span>
var elemText = elems[i].innerHTML;
elems[i].innerHTML = '';
for (var n = 0; n < elemText.length; n++) {
elems[i].innerHTML = elems[i].innerHTML + '<span>' + elemText[n].replace(' ', ' ') + '</span>';
}
// Loop through spans and apply mouse events
var nodes = elems[i].childNodes;
for (var n = 0; n < nodes.length; n++) {
// Mouseover - add focus classes
nodes[n].addEventListener('mouseover', function () {
// Main focus class
this.className = 'text-fx-focus';
// Left subfocus
if (this.previousSibling !== null) {
this.previousSibling.className = 'text-fx-subfocus';
}
// Right subfocus
if (this.nextSibling !== null) {
this.nextSibling.className = 'text-fx-subfocus';
}
});
// Mouseout - remove focus classes
nodes[n].addEventListener('mouseout', function () {
// Loop all spans from parent element
var spans = this.parentElement.childNodes;
for (var c = 0; c < spans.length; c++) {
spans[c].removeAttribute('class');
}
});
}
}
}
}
textFx.init();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.