text - bigger / smaller

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

text - bigger / smaller

Post by spamyboy »

Code: Select all

function zoomText(Accion,Elemento){
obj=document.getElementById(Elemento);
if (obj.style.fontSize==""){
obj.style.fontSize="100%";
}
actual=parseInt(obj.style.fontSize);
incremento=10;
if(Accion=="reestablecer"){
obj.style.fontSize="100%"
}
if(Accion=="aumentar"){
valor=actual+incremento;
obj.style.fontSize=valor+"%"
}
if(Accion=="disminuir"){
valor=actual-incremento;
obj.style.fontSize=valor+"%"
}
}
How to make that it would be not possible to make text smaller then 70% and larger than 130% ?
Pleas help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Add checks against those sizes....
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Code: Select all

function zoomText(Accion,Elemento){
obj=document.getElementById(Elemento);
if (obj.style.fontSize==""){
obj.style.fontSize="100%";
}
actual=parseInt(obj.style.fontSize);
incremento=10;
if(Accion=="reestablecer") {
obj.style.fontSize="100%"
}
if (Accion=="aumentar") {
if (obj.style.fontSize<="130%"){
valor=actual+incremento;
obj.style.fontSize=valor+"%"
}}
if (Accion=="disminuir"){
if (obj.style.fontSize!="70%"){
valor=actual-incremento;
obj.style.fontSize=valor+"%"
}}
}
This one almost works, but still now, pleas help.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Why are you using != on 70%?
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

works

Post by spamyboy »

Code: Select all

function zoomText(Accion,Elemento){
obj=document.getElementById(Elemento);
if (obj.style.fontSize==""){
obj.style.fontSize="100%";
}
actual=parseInt(obj.style.fontSize);
incremento=10;
if(Accion=="reestablecer") {
obj.style.fontSize="100%"
}
if (Accion=="aumentar") {
if (obj.style.fontSize!="130%"){
valor=actual+incremento;
obj.style.fontSize=valor+"%"
}}
if (Accion=="disminuir"){
if (obj.style.fontSize!="70%"){
valor=actual-incremento;
obj.style.fontSize=valor+"%"
}}
}
feyd | :?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Haha, no no no. I was pointing out what you probably did wrong, not right.

What I think you want to do is: (this is pseudo code BTW)

if(fontSize > '130%') fontSize = '130%';
else if(fontSize < '70%') fontSize = '70%';

Right?

(Don't take that word for word... You'd have to parse the strings as integers first.)
Post Reply