/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Font Size Aspect Ratio Change with Window Size

Just curious. Have a situation where da boss wants our a large piece of our site to be fully dynamic and integrated on any screen size.
This means changing font on size.
Well I cam up with a solution, figured if no one has one better, then i’ll share,
otherwise, I’d like to see better suggestions as my method is rather lengthy and by no means the prettiest piece i’ve written.

[B]My Solution[/B]
1.) while building each element, i only use “em” for font sizes.
Why? Simply, “1em” will always = your document/body’s font size setting

2.) With that in mind I just need to adjust the base font size according to window size.
Why? Simple, using jQuery (so nice n easy) i can do somthing as simple as
$(window).width(); to get the full “viewable” area (not to be confused with screen.width, which will return actual screen size)

3) the Function

[CODE]
function resizeDefFont()
{
var currentWindowWidth = $(window).width();

if (currentWindowWidth >= 900)
{
document.body.style.fontSize = ’16px’;
}
else if ((currentWindowWidth < 900) && (currentWindowWidth >= 875))
{
document.body.style.fontSize = ’15px’;
}
else if ((currentWindowWidth < 875) && (currentWindowWidth >= 800))
{
document.body.style.fontSize = ’14px’;
}
else if ((currentWindowWidth < 800) && (currentWindowWidth >= 725))
{
document.body.style.fontSize = ’13px’;
}
else if ((currentWindowWidth < 725) && (currentWindowWidth >= 700))
{
document.body.style.fontSize = ’12px’;
}
else if ((currentWindowWidth < 700) && (currentWindowWidth >= 625))
{
document.body.style.fontSize = ’11px’;
}
else if ((currentWindowWidth < 625) && (currentWindowWidth >= 550))
{
document.body.style.fontSize = ’10px’;
}
else
{
document.body.style.fontSize = ‘8px’;
};
// this is used privately as an easy way to get a var for default font size for other scripts that may check against it in order to determine sizes
//if your curious, the divFontSize is a div box with no opacity, a z-index of -whatever and height and width of 1em, thus it will always give me the default font size
defFontSize = $(“#divFontSize”).height();
}
[/CODE]

finallly, i run the code on start as well as binding to the window resize event.

Seems to work great with no flaws (thus far).
Any suggestions? any praise? ?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@tracknutApr 14.2011 — No offense to da boss, but this is going to be a very non-standard user experience. How many web sites have you browsed where the font size changes as you increase or decrease the size of your browser window? None, in my case. People don't expect a site's font size to be proportional to the window size; they expect it to be rather consistent across all sites they browse, regardless of the window size.

Dave
Copy linkTweet thisAlerts:
@SpYk3authorApr 14.2011 — that's unacceptable and also very untrue

if that were true, there wouldn't be 10 different plugins for just that

i simply don't like the plugins because none are based to work as simply as i want them too, they are full of extra functions to do extra work and determine exorbitant amounts of useless information to my cause

also, check out just about any sight that is both pc and handheld friendly and you'll find alot of dynamic font size aspect changes

i see it everyday

as i mentioned before, i dont really like this method, but i've yet to find an easier solution

posting your opinion on not liking a font change doesn't mean it doesn't exist and is not useful to anyone

Thank you
Copy linkTweet thisAlerts:
@tracknutApr 14.2011 — I'd really like to see an existing site that you're referring to. As I say, I've never seen one, so please show me just one.

Sure, there are sites that distinguish between mobile and desktop platforms, but a site that changes every 75 pixels all the way up? Never seen such a thing, and like I say it is not at all the user interface model that is common on the web.

Dave
Copy linkTweet thisAlerts:
@SpYk3authorApr 14.2011 — then what is the comon user interface for dealing with a fully resizable, fully dynamic page where everysingle cell of the page is it's own dynamically loaded element?

And i appologize, entire site font size changes aren't standard, however, changing font size with window size is standard for elements such as custom toolbars, sliders, and pic organizers, the difference here is, our entire program is encased within one window view and should never have to scroll to see any part, thus the need for changing font sizes

i should also mention, i ddn't do this for a typical page, but for a program built entirely from php and javascript. with use of a sql database of course. So it's not like its a normal feature for the net, but quite frankly, i'm sick of blueprint layouts myself, it's the modern age, i shouldn't have to scroll any website, as far as i'm concerned, all things on the web should fit directly in my browser window and only elements within the page should actually scroll. after all, i do more surfing from my win 7 phone than my pc, and scrolling pages set to default size are more than annoying. UPGRADE. we have html 5 and css3 with things like font-stretch seeking to elimante such problems as need for this very function because of what i'm talking about. and fyi, sites to be fully mobile can no longer depend on php to determine browser type and redirect, as my winphone's IE shows as IE9, not mobile, therefor pages don't redirect me, but rather send me to the standard pc pages. I don't this as a flaw of the smart phone, but rather a flaw of the page designer for not making their page more dynamic.
Copy linkTweet thisAlerts:
@tracknutApr 14.2011 — Well the common interface if you want pages to fit into the browser window is to make them fluid, and have the images move closer together while the text wraps around them. Normally those images stay the same size regardless of browser window size, and if you want a fluid site that shrinks down to say 800px for a small desktop screen, you can't of course put images wider than that. Yes, menus often shrink down to stay on one line. And yes, a fluid site will typically scroll vertically as you shrink it down.

I'm not saying you can't develop what you have in mind, I'm just saying it is not at all normal on the web. If you are tired of sites where the objects remain the same size, go right ahead with your plans to make everything scale up and down with no scrolling!

Dave
Copy linkTweet thisAlerts:
@SpYk3authorApr 14.2011 — lol, belive me, i will, for the job i have no choice.

but for personal, i'd still like to see more sights get fully fluid, still no reason for this to not be standard, thus the reason css3 provides a simple solution

of course not all browsers are up to par yet

but give it time, all things evolve, eventually
Copy linkTweet thisAlerts:
@SpYk3authorApr 14.2011 — and sorry if i seem agitated, personal life crap is ticking me off (married)
×

Success!

Help @SpYk3 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...