Fade with jQuery while also changing font-style and text
# April 7, 2013 at 7:15 pm
I’m setting up a possible colophon for my about page to display the webfonts I’m using. I’m wondering if it was possible to have jQuery do the following:
+ Fade cycle from Aa to Zz
+ Change font-style from normal to italic before switching to the next characters
Example ( “=>” represents fading ):
Aa => Aa => Bb => Bb…etc# April 7, 2013 at 11:31 pm
Is there any way to condense this down further and also perhaps comment it so I can make adjustments?
There seems to be a delay from roman to italic so I’m trying to figure out the code to solve it.
Update: Chris told me that CodePen strips `fromCharcode` as it’s a security risk for them. I wonder if it’s a security risk in general as I found it on some XSS tutorials. Kind of makes me a bit nervous.# April 8, 2013 at 2:50 am
I’ve updated your fiddle to include comments too so you can understand whats going on,
Edit: Sorry, totally forgot to add the link :)
fromCharcode can be used for malicious purposes as its a great way to mask values that may otherwise be sanitized,
for example, if you execute the following in the browser console
alert(String.fromCharCode(67, 83, 83, 32, 84, 114, 105, 99, 107, 115, 32, 82, 111, 99, 107, 115, 33, 33));
You’ll see that it will return a string representation of the char codes, this could be used to evaluate a function name or similar that would normally be stripped out of user input,
However, it is a very userful function for situations like this one where we need to programaticly manipulate strings based on it’s charcode,# April 8, 2013 at 10:48 pm
Sorry to bug again, there seems to be a noticeable difference in the fading. It looks fine when it fades into the italics but from the italics to roman, it seems a bit faster. Also, even with commenting the JS, it’s still a bit complicated to edit.
And would it be possible to only allow the cycle to happen when the whole entire div is hovered?# April 9, 2013 at 4:31 am
Can maybe help you on the fade bug, edit line 29 to:
because `$(this).removeAttr(‘style’);` removes the opacity added by jQuery’s fade function too. Hope that helps.
EDIT: That and the total interval time is 4000ms, each fade is 200ms and the normal state is 2000ms… so that leaves 1200ms for the italic state since there are 4 fades total (4000 – 4×200 – 2000). You can either make the total interval time 4800ms or the normal state 1600ms.
Another EDIT: @Podders, the problem with using an interval is they sort of ‘keep running’ when the window loses focus. So when your tabbed out for a while and come back it skipped half the alphabet. Maybe it doesn’t matter here but else using timeouts instead might help.# April 9, 2013 at 5:39 am
@CrocoDillon Well, that makes sense and your updates seemed to work. Thanks for the help.
@Podders Hopefully you haven’t started yet. I think we should hold off on this until I’m certain this is what I would like as I’m still testing the layout on my about page. I’m having a few issues on the layout therefore, I need to tweak a few things, first. And I’d rather not waste your time at this stage.
You must be logged in to reply to this topic.