agkamerer Forum Regular

Joined: 08 Mar 2005 Posts: 396 Location: Alabama, USA
|
Posted: Wed Apr 09, 2008 7:39 pm Post subject: Font-size changer? |
|
|
I've seen this feature on blogs a few times, and I think it'd be a useful one to add to my webnovel, as it would allow readers to change the font size to suit their tastes. Yes, I know they could do it themselves through the browser controls, but I like the idea of an on-site button they could use.
What I'm looking for is something that provides a button that allows the user to either increase or decrease the font of a post (preferably, just the content of a blog post, not the rest of the site) instantly. I'm fairly certain it's done with AJAX.
I use wordpress for my webnovel, so if anyone knows of a plugin that gives this capability, I'd love to see it.
Thanks a lot.  _________________ Gloria Fidelis: A Steampunk Fantasy |
|
krt ...

Joined: 11 Jan 2005 Posts: 4607 Location: Australia
|
Posted: Thu Apr 10, 2008 12:12 am Post subject: |
|
|
It's done in JS:
JavaScript: | Code: | function changeFontSize(amount) {
var ele = document.getElementsByTagName('body')[0].style;
if (!ele.fontSize) ele.fontSize = '75%';
var newAmount = Math.round((ele.fontSize.subs_tring(0, ele.fontSize.length-1)) * (1+(amount/2/100)));
ele.fontSize = Math.round(newAmount) + '%';
} |
NOTE: In the above, remove the underscore (_) in subs_tring, the paranoid filters here don't allow that word
And the HTML for the decrease/increase links:
| Code: |
<a href="javascript:changeFontSize(-10);" style="font-size: 100%;">A</a>
<a href="javascript:changeFontSize(100/9);" style="font-size: 125%;">A</a> |
I don't see how you thought it would be AJAX though, are you sure you know what AJAX is and what it is for? The only possible application of it here that I can think of is something that re-calculates character widths but even that would be stored statically. |
|