workaround for display block and css transitions not triggering

后端 未结 4 778
一个人的身影
一个人的身影 2021-01-12 21:16

Sorry all for so many updates in this question and I\'m glad for everyone trying to help me. I think below there is a more clear way to understand this problem:

4条回答
  •  一个人的身影
    2021-01-12 21:38

    If you just add a timeout to the opacity call it should work! The duration can be almost nothing, as long as the display and opacity properties don't get called at the same time.

    var dom = {};
    dom.creative = document.getElementById('creative');
    dom.creative.style.display = 'block';
    setTimeout(function(){
      dom.creative.style.opacity = 1;
    },1);
    

    You can also use a jQuery fadein, if jQuery is an option. Then you can leave out the opacity altogether and just call it like...

    dom.creative.fadeIn(500)
    

提交回复
热议问题