2009-08-26 56 views

回答

1

HTML:

<script type="text/javascript" src="jquery-1.3.2.min.js"></script> 
<script type="text/javascript" src="jquery-ui-1.7.2.custom.js"></script> 
<link rel="stylesheet" type="text/css" href="ui.all.css"/> 

<div id="container" class="ui-widget-content" 
    style="font-size:10px;width:100px;height:100px;padding:0.5em;">   
    <div class="ui-widget-header">Resize This</div> 
    this is some text. this is some text. this is some text. this is some 
    text. this is some text. this is some text. this is some text. this is 
    some text. this is some text. this is some text. this is some text. 
</div> 

的jquery:

var oh=0; //original height of container 
    var ow=0; //original width of container 
    var fs=10;//original font size 

    $(document).ready(function(){ 
     oh=$("#container").height(); 
     ow=$("#container").width(); 

     $("div#container").resizable({ 
      stop: function(element,ui){ 
       var h=ui.size.height; 
       if(oh==0) return; 
       var nfs = (h/oh) *fs; 
       $("#container").css({'font-size':nfs+"px"}); 
      }, 
      ghost: true 
     }); 
    }); 
+0

這可以通過將全局變量的主要功能的範圍內進行優化 – Jason