javascript - Select a specific character in a string and offset it (visually) with Jquery -


I'm trying to use Jquery / Javascript to duplicate a broken typewriter font (since I do not have any met). But I want to make it random, which breaks the letter. I was able to split the string of the ID that I wanted and used a bit of code, I got a random number between 0 and the total length of the string. Now what's the problem with me, doing something with that particular character? I want to push it down or a few pixels. I was trying to give it a class so I can add some margins or padding, but this work does not do. So where am I now, where am i

Here's the page, I'm trying to do it in the word "ABOUT":

Here's the script:

  Lt; Script type = "text / javascript" & gt; Function Random Box (Minall, Maxwell, Flat Val) {var Randwall = Minimal + (Math.Random) * (Max-V-Minval)); Return type of float valve == 'undefined'? Mathrade (Randwall): Randwall Fix (flat val); } Var str = $ ('# typehead'). Text (); Var strcnt = str.length; Var explosion = str.split (''); Var rdmltr = randomxtoY (0, strcnt); Var theLetter = explosion [rdmltr]; TheLetter.addClass ("NewClass"); Var toffset = $ ('newclass') Offset (); Warning (toffset.left + "," + toffset.top); & Lt; / Script & gt;  

edit: updated to make sure Has been found that the matching character function randomXToY (minVal, maxVal, IME), flat val) {var randomwall = minal + (Math.Rendam) * (Max-VL-Minval)); Return type of float valve == 'undefined'? Mathrade (Randwall): Randwall Fix (flat val); } Var explosion = $ ('#typehead'). Text (). the division (''); Var rdmltr = randomxtoY (0, explosion length); // Make sure we do not get a space character (explosion [rdmltr] == '') {rdmltr = randomxtoY (0, explosion length); } // Wrap a letter with a spin that has a new class and it is updated in the array [rdmltr] = '& lt; Span class = "newClass" & gt; + Explosion [rdmltr] + '& lt; / Span & gt; '; // Update content $ ('#typehead'). Html (Explode. ('')); Var toffset = $ ('newclass') Offset (); Warning (toffset.left + "," + toffset.top);

Update: If you want to apply it to several:


Comments