简体   繁体   English

jQuery动画方法无法在Chrome和IE中同时为两个div边距动画(在FF中有效)

[英]jQuery animate method fails to animate two divs margins at same time in Chrome and IE (works in FF)

I am trying to get a div to slide left and right moving in and out of visibility using the jQuery animate method to adjust the margins of two side by side divs. 我正在尝试使用jQuery animate方法调整左右并排div的边距,以使div向左和向右滑动进出可视范围。

In Firefox this works smoothly. 在Firefox中,此操作很流畅。 In IE and Chrome it seems like one of the divs margins is animating but the other is failing to until the first div's animation is complete. 在IE和Chrome中,似乎一个div边距正在设置动画,但是另一个在直到第一个div的动画完成之前都没有。

Here is a JSFiddle: http://jsfiddle.net/1uq99nxx/1/ 这是一个JSFiddle: http : //jsfiddle.net/1uq99nxx/1/

Here is the jQuery code: 这是jQuery代码:

$( "div#PrevButton" ).click(function() {
    $( "div#ACHPanel" ).animate({
        marginLeft: '-=730px'
    }, { duration: 1000, queue: false });
    $( "div#SummaryPanel" ).animate({
        marginLeft: '+=730px'
    }, { duration: 1000, queue: false });
});

$( "div#NextButton" ).click(function() {
    $( "div#ACHPanel" ).animate({
        marginLeft: '+=730px'
    }, { duration: 1000, queue: false });
    $( "div#SummaryPanel" ).animate({
        marginLeft: '-=730px'
    }, { duration: 1000, queue: false });
});    

I mostly just changed your css elements positioning and added a couple wrappers. 我主要只是更改了您的CSS元素的位置,并添加了一些包装器。

http://jsfiddle.net/1uq99nxx/3/ http://jsfiddle.net/1uq99nxx/3/

I put the right bar into a wrapper that's absolute positioned to the right of the container. 我将右栏放入包装盒中,该包装盒绝对位于容器的右侧。 I also put the email bar at the bottom in a wrapper that's also absolute positioned. 我还将电子邮件栏放在包装纸的底部,该包装纸也是绝对放置的。

The CSS: CSS:

div#ACHPanel {
    float: left;
    height: 360px;
    width: 230px;
    padding: 0px 10px 10px 10px;
}

div#ACHPanelWrapper {
    width: 256px;
    padding: 0; 
    background-color: #A6B0D2;
    position: absolute;
    top: 0;
    right: 0;
    z-index: 0;
}

div#emailWrapper {
    margin: 0 10px 0 0;
    position: absolute;
    top: 410px;
    right: 0;
}

Your jQuery didn't change much. 您的jQuery并没有太大变化。 I just removed the references to the ACH box. 我刚刚删除了对ACH框的引用。

$( "div#PrevButton" ).click(function() {
    $( "div#SummaryPanel" ).animate({
        marginLeft: '+=730px'
    }, { duration: 1000, queue: false });
});

$( "div#NextButton" ).click(function() {
    $( "div#SummaryPanel" ).animate({
        marginLeft: '-=730px'
    }, { duration: 1000, queue: false });
});

You may need to adjust the css a bit to get your spacing exactly the way you want but this works across chrome, firefox and IE. 您可能需要稍微调整css,以完全按照您想要的方式获得间距,但这在chrome,firefox和IE中都可以使用。

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

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