English 中文(简体)
封闭元素,但集装箱集中
原标题:Animate element, but keep container centered

我目前正在研究一个习俗灯塔,需要一些援助。 我的印象是,将工作重心转作形象,但我陷入了一个小问题。 灯塔见用户屏幕中,但一旦我清醒过宽和高高,它就没有留在屏幕的中心,只是使用old<>/strong>左和高价值。

此处标明灯塔本身:

<div id="jqgal_container">
    <div id="jqgal_nav_left" class="jqgal_nav">&lt;</div>
    <div id="jqgal_main">
        <div id="jqgal_main_img"></div>
        <div id="jqgal_footer">
            <div id="jqgal_main_caption"><p></p></div>
            <div id="jqgal_thumbnav_left" class="jqgal_thumbnav">&lt;</div>
            <div id="jqgal_thumbs">
                <div id="jqgal_thumbs_container">
                    <ul></ul>
                </div>
            </div>
            <div id="jqgal_thumbnav_right" class="jqgal_thumbnav">&gt;</div>
        </div>
    </div>
    <div id="jqapp_nav_right" class="jqgal_nav">&gt;</div>
</div>

图像将储存在<代码>#jqgal_main_img内,作为<img />要素。 I animate the width and high of #jqgal_main_img,但我还想将整个集装箱(#jqgal_container)放在屏幕上。

我的问题是,我怎么能把儿童元素的宽度同起来,但还是分别把顶和左边放在集装箱的位置上,从而似乎从中心扩大和成长?

现行图像集装箱的宽度和高度的代码如下:

_resizeToFit : function(img_width, img_height, compFunc)
{
    // Calculate the width and height needed:
    var req_width  = img_width;
    var req_height = img_height;

    this._elements.mainimg.animate({ width: req_width }, {
        duration:  fast ,

        complete: function() {
            $.jqgal._elements.footer.width(req_width);
            $.jqgal._elements.mainimg.animate({ height: req_height },  fast , function() {
               if(compFunc != undefined) { compFunc.call(this); }
            });
        },

        step : function() {


        }
    });
}
最佳回答

此外,还计算出差额和差值:

  "margin-left" : ($(window).width() - req_width) / 2 
  "margin-top" : ($(window).height() - req_height) / 2

如果CSS职位是绝对的,则将差值上限/差值转移到顶和左边。

EDIT:

在整段试射中,添加

.parent().animate({
          "margin-left" : )($(window).width() - req_width) / 2) + this._elements.mainimg.parent().scrollLeft(),
  "margin-top" : (($(window).height() - req_height) / 2 ) + this._elements.mainimg.parent().scrollTop()
}}

或者在警示职能中:

$(this).parent().animate({...});

为方便起见,最好确定具有要素的变量......

$this = this._elements.mainimg;
$parent = $this.parent();

然后,母体的对应数据将考虑:

         "margin-left" : )($(window).width() - req_width) / 2) + $parent.scrollLeft(),
  "margin-top" : (($(window).height() - req_height) / 2 ) + $parent.scrollTop()
}}

哪一点容易读!

问题回答

i 认为你应当把差值与距离分开。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.