Javascript 什么';如果转换发生,让JS回调等待CSS3转换的健壮方法是什么?

Javascript 什么';如果转换发生,让JS回调等待CSS3转换的健壮方法是什么?,javascript,css,event-handling,css-transitions,transitionend,Javascript,Css,Event Handling,Css Transitions,Transitionend,在过去的JS转换中,可以通过回调指定转换后发生的某些行为。例如 //jQuery function hideTheContent() { $('#content').fadeOut(1000,function() { mandatoryLogicAfterHidingContent(); }); } 现在有了CSS3转换,我们可以做类似的事情 //CSS #content { opacity:1; transition: opacity 1s; } .hi

在过去的JS转换中,可以通过回调指定转换后发生的某些行为。例如

//jQuery
function hideTheContent() {
    $('#content').fadeOut(1000,function() {
      mandatoryLogicAfterHidingContent();
    });
}
现在有了CSS3转换,我们可以做类似的事情

//CSS
#content {
  opacity:1;
  transition: opacity 1s;
}

.hidden {
  opacity:0;
  transition: opacity 1s;
}

//jQuery
function hideTheContent() {
    $('#content').addClass('hidden');
    // still need to run mandatoryLogicAfterHidingContent
}
我知道新的过渡事件,所以假设我们可以这样做:

//jQuery
function hideTheContent() {
    $('#content').on('transitionend', function(e) {
      mandatoryLogicAfterHidingContent()
    })

    $('#content').addClass('hidden');
}
但是由于我们现在将JS从UI中分离出来,有可能其他人会提供一个新的UI,其中内容隐藏是即时的,删除CSS3转换,并无意中中断对mandatoryLogicAfterHidingContent()的JS调用

另一种情况是,假设我有一个长方体,有一个重置函数,该函数将长方体的大小调整为50x50(带有转换),然后调用mandatoryLogicAfterResize()。如果我调用reset fn两次,我认为在这种情况下不能保证触发转换事件,但是我仍然需要mandatoryLogicAfterResize来运行这两次

在更复杂的代码库中,我还担心在我所针对的特定转换之前调用其他转换。并提前触发mandatoryLogic()。我想这里的核心问题是,在CSS3转换中,如何将mandatoryLogicAfterHidingContent()事件处理程序与我调用的
addClass('hidden')
绑定起来,就像我调用jQuery回调一样