Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS equivalent to using Ctrl+Mousewheel up/down on webpages?

Status
Not open for further replies.

cyberspace

Technical User
Joined
Aug 19, 2005
Messages
968
Location
GB
I am wanting to allow users to resize text on a website I am developing via clicking an option in the menu to increase/decrease text size.

I tried this code:

Code:
var min=8;
var max=18;
function increaseFontSize() {
var p = document.getElementsByTagName('p');
for(i=0;i<p.length;i++) {
if(p[i].style.fontSize) {
var s = parseInt(p[i].style.fontSize.replace("px",""));
} else {
var s = 12;
}
if(s!=max) {
s += 1;
}
p[i].style.fontSize = s+"px"
}
}

But, this only increases static text, and has no effect on text coming from the database, such as the newsfeed.

However, if I hold ctrl and roll the mouse wheel in either direction, everything is increased/decreased proportionately.

I was wondering if there is a JS equivalent to this? (or indeed any other type of equivalent that could be tied to a link/button)

Thanks :)

'When all else fails.......read the manual'
 
JavaScript shouldn't care where the data is coming from. As far as it knows, it's all static text. Your code is only affecting text in <P> tags. Is it possible that your database data is wrapped in some other tag?

You could also look into the zoom attribute supported by IE.

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top