CSS3 Transition: Different transition for *IN* and *OUT* (or returning from transitioned state)

前端 未结 1 1167
一生所求
一生所求 2021-01-01 16:34

Original Question... updated working code below:

I have a loading image which comes up during an ajax load event. The image shows/hides by

1条回答
  •  伪装坚强ぢ
    2021-01-01 16:53

    Here is a simplified test case:

    div {
        background: blue;
        opacity: 0;
        transition: opacity 2s ease-in-out;
    }
    
    div.loading {
        opacity: 1;
        background: red;
        transition: opacity 2s ease-in-out, background 1s ease-in;
    }
    

    Notice how the opacity fades the same in and out, but the background only fades in, and immediately turns blue on fade out.

    I used :hover as an example, but it should work the same when adding and removing classes with JavaScript.

    Demo

    If you'd like a more specific example please provide a reduced test case on dabblet or Jsfiddle.

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