简体   繁体   English

Chrome,Firefox和Opera中的CSS转换问题,但IE中没有

[英]Issue with CSS transitions in Chrome, Firefox and Opera, but not IE

In my web application, I want to animate switching between two elements. 在我的Web应用程序中,我希望动画化两个元素之间的切换。 The old element should disappear by sliding off to the left and fading out at the same time, after which the new element appears by sliding in from the right while fading in. 老元素应通过向左滑动并同时渐出而消失,此后,新元素通过渐入时从右侧滑动而出现。

Please see this fiddle: http://jsfiddle.net/mtKaz/8/ 请查看此小提琴: http : //jsfiddle.net/mtKaz/8/

I am trying to use CSS transitions for the animation. 我正在尝试对动画使用CSS过渡。 Everything works fine on first iteration, however once an element has been hidden once, the transition for the appearing element stops working: the appearing element just snaps in, without any motion or fading. 在第一次迭代中一切正常,但是一旦元素被隐藏一次,出现元素的过渡就停止工作:出现元素只是捕捉,没有任何运动或褪​​色。

I am experiencing this problem in Chrome, Opera Next and Firefox, but not in IE10. 我在Chrome,Opera Next和Firefox中遇到此问题,但在IE10中却没有 Am I doing something wrong or is this a bug in all browsers but IE (a most bizarre notion)? 我是在做错什么还是这是除IE(最奇怪的概念)以外的所有浏览器中的错误?

The issue seems to be related to show() / hide() , since there is no problem if I set the elements to position: absolute and remove the show() / hide() calls. 这个问题似乎与show() / hide() ,因为如果将元素设置为position: absolute ,则没有问题position: absolute并删除show() / hide()调用。

JavaScript: JavaScript:

var currentDiv = "div2";

$(function(){
    $('#btn').click(function(){
        var newDiv = currentDiv == 'div1' ? 'div2' : 'div1';
        var oldDiv = currentDiv;

        // Start transition for the disappearing div
        $('#' + oldDiv).css({ opacity: 0, left: -100 });

        // Prepare the new div for showing by first moving it to the right
        // There will be a transition here as well, but it won't be visible
        $('#' + newDiv).css({ opacity: 0, left: +100 });

        setTimeout(function(){
            // Once the transition is done, hide the div so it doesn't occupy space
            $('#' + oldDiv).hide();
            // Show the new div and immediately start its appearing transition
            $('#' + newDiv).show().css({ opacity: 1, left: 0 });
        }, 1000);

        currentDiv = newDiv;
    });    
});

CSS: CSS:

.myDiv {
    position:relative;
    transition: left 1s, opacity 1s;
    width: 200px;
}

HTML: HTML:

<div id="div1" class="myDiv" style="display:none">
    hello, this is some text
</div>
<div id="div2" class="myDiv" style="display:none">
    and here is some more text
</div> 

There are issues with animating elements, which start with the attribute display: none. 动画元素存在一些问题,这些问题始于属性显示:无。 Wait for the complete callback of show() and then set the css properties. 等待show()的完整回调,然后设置css属性。

$('#' + newDiv).show(400, function(){
$(this).css({ opacity: 1, left: 0 });
});

See documentation for details: http://api.jquery.com/show/#show-duration-complete 有关详细信息,请参见文档: http : //api.jquery.com/show/#show-duration-complete

暂无
暂无

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

相关问题 CSS无法在IE,Firefox,Opera中加载,并且无法与Chrome和Safari正常运行 - Css not loading in IE,Firefox,Opera and working fine with Chrome and Safari jQuery .css()在IE 6,7,8和Firefox中不起作用,但在Chrome,Safari,Opera中起作用 - jQuery .css() not working in IE 6,7,8 and Firefox, but works in Chrome, Safari, Opera javascript在chrome / opera / IE中不起作用,但是firefox非常好! - javascript not working in chrome/opera/IE but firefox is excellent! HTML / JavaScript简单重定向-可以在IE / Opera中运行,但不能在Chrome / Firefox中运行 - HTML/Javascript simple redirect -works in IE/Opera but not in Chrome/Firefox Canvas drawImage - firefox / opera / ie(不是chrome)中tile的可见边缘 - Canvas drawImage - visible edges of tiles in firefox/opera/ie (not chrome) Jplayer音频不能在Firefox,Opera和IE中运行,但可以在Chrome中使用 - Jplayer audio not working in firefox, opera and IE but works in Chrome Javascript / jQuery无法在Firefox,Safari和IE中运行。 精通Opera和Chrome - Javascript/jQuery not working in Firefox, Safari and IE. Fine in Opera and Chrome Chrome,IE,Opera,Safari上的iFrame溢出x错误,但Firefox上没有 - iFrame overflow-x BUG on Chrome, IE, Opera, Safari but not on Firefox 该Javascript在IE中不起作用,但在Chrome,Firefox和Opera中起作用 - This Javascript doesn't work in IE but works in Chrome, Firefox and Opera JavaScript代码仅在Chrome中有效,而在Firefox,IE,Opera和Safari中无效 - JavaScript code working only in Chrome but not in Firefox, IE, Opera and Safari
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM