CSS transition doesn't work in Firefox when position is changed

后端 未结 1 559
南笙
南笙 2020-12-31 08:26

I\'ve found annoying bug. I try to animate CSS properties of child elements when at the same time position of parent is changing (in the example it\'s from fixed to absolute

相关标签:
1条回答
  • 2020-12-31 09:24

    It seems you have found a good bug. Although this isn't my favorite fix, it does the job. Change your button2 to do this on click.

    $("#button2").on({
        click: function() {
            $("#container").toggleClass("some_state");
    
            setTimeout(function() {
                $("#container").toggleClass("some_state_position");
            }, 50);
        }
    });
    

    It appears for firefox the toggleClass() fires immediately for both classes, causing some issues with the transition effects. Putting the timeout gives jQuery the enough time for it to process what it needs to, in order to do the transitions similar to those in Chrome, etc. I put the timeout to 50ms, this appears to give it enough time for jQuery to process what it needs to do. Going lower than that I saw sometimes, it fail and do what you are currently experiencing.

    0 讨论(0)
提交回复
热议问题