zoom - Jquery size text -


i've created script supposed increase or decrease size of text (shown below) problem text remaining same size when click on 1 of images , pass parameter menos

<script>  function increase_text(size,mode) {      var size_ini=16;     var size_max=20;     var size_min=16;       if (mode=="mas")     {         var size_increase = size_ini++;          alert("ok"+size_increase);          if (size_increase<20)         {             $(".content").css("font-size",""+size_increase+"px");         }         else         {             $(".content").css("font-size",""+size_max+"px");         }     }       if (mode=="menos")     {         var size_increase = size_ini--;          if (size_increase>=20 || size_increase>=size_min)         {             $(".content").css("font-size",""+size_increase+"px");         }         else         {             $(".content").css("font-size",""+size_min+"px");         }     } } </script> 

markup

<div style="position:relative;width:100%;border:0px solid;height:40px;"> <img src="http://127.0.0.1/tfw_end/wp-content/themes/thefactoyweb/images/text_decrease.png" onclick="increase_text('1','menos');" style="display:block;float:right;cursor:pointer;cursor:hand;" alt="aumentar texto" title="aumentar texto"> <img src="http://127.0.0.1/tfw_end/wp-content/themes/thefactoyweb/images/text_increase.png" onclick="increase_text('1','mas');" style="display:block;float:right;cursor:pointer;cursor:hand;" alt="reducir texto" title="reducir texto"></div> 

http://jsfiddle.net/wn6yj/

regards

there multiple problems
1. size_ini local variable, means reset on every call of increase_text
2. there problem in incremental/decremental logic also, though size_ini more size_max kept incremented, on next decrease click text shown in bigger font allowed.

use

var size_ini = 16; var size_max = 20; var size_min = 16;  function increase_text(size, mode) {     if (mode == "mas") {         size_ini = size_ini >= size_max ? size_max : size_ini + 1;     } else if (mode == "menos") {         size_ini = size_ini <= size_min ? size_min : size_ini - 1;     }     $(".content").css("font-size", size_ini + "px"); } 

demo: fiddle


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -