Home › Forums › JavaScript › Fade with jQuery while also changing font-style and text
- This topic is empty.
-
AuthorPosts
-
April 7, 2013 at 7:15 pm #43947
chrisburton
ParticipantI’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 8:39 pm #130947Podders
ParticipantHad to change to a fiddle, it seems that codepen strips out the fromCharCode from the js,
You may have to play around with the timing and css to get it perfect but the functionality is here
April 7, 2013 at 8:56 pm #130948chrisburton
ParticipantAwesome, thank you! I’ll take a look as soon as I arrive home.
April 7, 2013 at 11:31 pm #130951chrisburton
ParticipantIs 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 #130958Podders
ParticipantI’ve updated your fiddle to include comments too so you can understand whats going on,
Edit: Sorry, totally forgot to add the link :)
http://jsfiddle.net/M3VvF/1/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 consolealert(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 3:00 am #130960chrisburton
ParticipantI really appreciate the help @Podders!
April 8, 2013 at 10:48 pm #131079chrisburton
ParticipantSorry 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 3:48 am #131098Podders
ParticipantSure, I’m at work at the moment so will take a look again on my lunch break,
April 9, 2013 at 4:31 am #131100CrocoDillon
ParticipantCan maybe help you on the fade bug, edit line 29 to:
$(this).css(‘font-style’,’normal’);
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 #131110chrisburton
Participant@CrocoDillon Well, that makes sense and your updates seemed to work. Thanks for the help.
Update:
@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. -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.