简体   繁体   English

jQuery动画按比例扩展

[英]jQuery animate expand proportionally

I'm now in problem about how to animate function in jQuery to expand proportionally. 我现在遇到有关如何在jQuery中对函数进行动画处理以按比例展开的问题。 Normally, it expand one-sided only just like expand to bottom or expand to right. 通常,它只像扩展到底部或扩展到右侧一样单面扩展。

What I want is to expand proportionally left-right-top-bottom by using animate. 我想要的是通过使用动画来按比例从左上右下扩大。

替代文字

Following is my coding. 以下是我的编码。 What I said above, it expand to bottom only. 我在上面说的只是扩展到底部。

$(document).ready(function() {
    var theFrame = $("#FrmPatient", parent.document.body);
    theFrame.animate({width: 650, height: 485}, 1000);
});         

Try this: 尝试这个:

<div id="frame"></div>

#frame {
    position: absolute;
    left: 50%;
    top: 50%;
    margin: -100px 0 0 -100px;
    width: 200px;
    height: 200px;
    background-color: #999;
}

$(function() {
    var w = 400, h = 400;
    $("#frame").animate({
        width: w,
        height: w,
        marginLeft: -w/2,
        marginTop: -h/2
    }, 1000);
});

http://jsfiddle.net/GVj83/ http://jsfiddle.net/GVj83/

You'll need to animate the left and top properties as well. 您还需要为lefttop属性设置动画。 If the original width and height of the box are (w0, h0) and the expanded ones are (w1, h1), animate left to left-(w1-w0)/2 , and top to top-(h1-h0)/2 . 如果框的原始宽度和高度为(w0,h0),展开的宽度和高度为(w1,h1),请从左动画(w1-w0)/ 2 ,从到上动画- (h1-h0)/ 2 Note that would only work with absolute or relative positioning. 请注意,这仅适用于绝对或相对定位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM