如何用jQuery实现调整大小动画?

时间:2009-08-26 16:30:32

标签: jquery animation resize

调整容器大小时,(文本)内的所有内容也应相应缩放。

是否有可以实现此目的的插件?

1 个答案:

答案 0 :(得分: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
         });
    });