skip to Main Content

I want to achieve this effect with a block of text, where each letter changes to either another font or icon on mouse-hover. I was unable to find the right terms to look up what something like this could be called. The link to the page is below. Once you hover on the text you will be able to see the effect;

http://www.other-studio.com/

3

Answers


  1. You would have to create a wrapper for each letter, and then use JavaScript to control the hover effect, or you could use CSS pseudo-elements.

    Here is how to do it using CSS ( My preferred way ):

    First, the html:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <link rel="stylesheet" href="./styles.css" />
      </head>
      <body>
        <div class="container">
          <span class="highlight" data-hover="A">a</span>
          <span class="highlight" data-hover="B">b</span>
        </div>
      </body>
    </html>
    

    Now, the CSS:

    .container {
      display: flex;
    }
    
    .highlight {
      padding: 10px;
      margin: 5px;
      background-color: lightblue;
      cursor: pointer;
      position: relative;
    }
    
    .highlight:hover::before {
      content: attr(data-hover);
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: lightcoral;
    }
    

    Change the data-hover to the desired hover value!

    If you want to change the font, here is how:

    document.querySelectorAll('.highlight').forEach(function(element) {
      element.addEventListener('mouseenter', function() {
        element.classList.add('changed');
      });
    });
    .container {
      display: flex;
    }
    
    .highlight {
      padding: 10px;
      margin: 5px;
      cursor: pointer;
      font-family: 'Arial', sans-serif;
      /* Default font */
      transition: font-family 0.3s;
    }
    
    .highlight.changed {
      font-family: 'Courier New', monospace;
      /* New font */
    }
    
    .highlight:hover {
      font-family: 'Courier New', monospace;
      /* Change to new font on hover */
    }
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    
    <body>
      <div class="container">
        <span class="highlight">a</span>
        <span class="highlight">a</span>
      </div>
    </body>
    
    </html>
    Login or Signup to reply.
  2. You can change a font in js by document.getElementById('id').style.fontFamily = "fontname";

    Or just CSS: element {font-family: name;} element:hover {font-family: new-name;}

    The source code of the font changing of your example site is here btw: http://www.other-studio.com/assets/bundle.js?v=1.2.7

    Login or Signup to reply.
  3. Not too difficult.

    I was able to replicate something similar to the example with some simple JavaScript.

    Note:
    You can insert any characters you want as a possible replacement for the original into the replacement symbols array.

    const replacementSymbols = {
        a: ['α', '@', 'ä', 'å', 'ª'],
        b: ['β', 'ß', 'Ъ', '♭', 'ƀ'],
        c: ['¢', '©', 'ç', 'č', 'ċ'],
        d: ['δ', 'ð', 'đ', 'ď', 'ɖ'],
        e: ['ε', 'ë', 'ē', 'ĕ', 'ė'],
        f: ['ƒ', 'ϕ', 'φ', 'ғ', 'Ƒ'],
        g: ['γ', 'ğ', 'ġ', 'ģ', 'ǥ'],
        h: ['η', 'ħ', 'ȟ', 'ĥ', 'ɦ'],
        i: ['ι', 'ï', 'ī', 'ĭ', 'į'],
        j: ['ĵ', 'ɉ', 'ǰ', 'ʝ', 'ϳ'],
        k: ['κ', 'ķ', 'ĸ', 'ƙ', 'қ'],
        l: ['λ', 'ľ', 'ĺ', 'ļ', 'ł'],
        m: ['μ', 'м', 'ɱ', 'ӎ', 'Ӎ'],
        n: ['η', 'ñ', 'ň', 'ŋ', 'ɲ'],
        o: ['σ', 'ø', 'ö', 'ő', 'º'],
        p: ['ρ', 'π', 'ψ', 'þ', 'ƥ'],
        q: ['ϙ', 'ҩ', 'ɋ', 'գ', 'ʠ'],
        r: ['я', 'ř', 'ŗ', 'ɍ', 'ɾ'],
        s: ['š', 'ş', 'ß', 'ś', 'ș'],
        t: ['τ', 'ť', 'ţ', 'ƭ', 'ț'],
        u: ['υ', 'ü', 'ū', 'ů', 'ű'],
        v: ['ν', 'ѵ', 'ѷ', 'ⱱ', 'ⱴ'],
        w: ['ω', 'ẁ', 'ẃ', 'ŵ', 'ẅ'],
        x: ['ξ', 'х', 'ҳ', 'ӽ', 'ӿ'],
        y: ['γ', 'ÿ', 'ý', 'ŷ', 'ƴ'],
        z: ['ζ', 'ż', 'ź', 'ž', 'ƶ']
    };
    
    document.querySelectorAll('.character-wrapper').forEach(wrapper => {
        const original = wrapper.querySelector('.character-original');
        const replacement = wrapper.querySelector('.character-replacement');
    
        wrapper.addEventListener('mouseover', () => {
            const originalChar = original.textContent.toLowerCase();
            const symbols = replacementSymbols[originalChar];
    
            if (symbols && symbols.length > 0) {
                const randomSymbol = symbols[Math.floor(Math.random() * symbols.length)];
                replacement.textContent = randomSymbol;
                original.style.display = 'none';
                replacement.style.display = 'inline';
            }
        });
    
    });
    <h1 class="ogg-header ogg-header--indent">
      <p>
        <!-- "The quick" -->
        <span class="character-wrapper">
          <strong class="character-original">T</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">h</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">e</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <span class="character-original">&nbsp;</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">q</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">u</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">i</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">c</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">k</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <span class="character-original">&nbsp;</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <!-- "brown fox jumps" -->
        <span class="character-wrapper">
          <strong class="character-original">b</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">r</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">o</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">w</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">n</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <span class="character-original">&nbsp;</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">f</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">o</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">x</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <span class="character-original">&nbsp;</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">j</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">u</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
        <span class="character-wrapper">
          <strong class="character-original">m</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <strong class="character-original">p</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <strong class="character-original">e</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <strong class="character-original">d</strong>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">&nbsp;</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">o</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">v</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">e</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">r</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">&nbsp;</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">t</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">h</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">e</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">&nbsp;</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">L</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">A</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">Z</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">Y</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">&nbsp;</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">d</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">o</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">g</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>
         <span class="character-wrapper">
          <span class="character-original">.</span>
          <span class="character-replacement" style="font-family: sans-serif; display: none;"></span>
        </span>   
      </p>
    </h1>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search