代码之家  ›  专栏  ›  技术社区  ›  V. Rubinetti

ontransitionend不启动/连接,但添加了监听功能

  •  1
  • V. Rubinetti  · 技术社区  · 7 年前

    下面是一个简化的测试用例:

    var div = document.createElement('div');
    div.classList.add('test');
    document.body.appendChild(div);
    window.setTimeout(
      function() {
        div.style.boxShadow = '0 0 100px blue';
        div.ontransitionend = function() {
          console.log('transition end');
        };
        div.onclick = function() {
          console.log('click');
        };
      }, 100);
    div.test {
      width: 100px;
      height: 100px;
      background: red;
      box-shadow: none;
      transition: box-shadow 1s;
    }

    onclick 消息,但转换的结束不会触发“转换结束”消息。将事件处理程序更改为这样可以工作:

    div.addEventListener('transitionend', function() { console.log('transition end'); } );
    

    addEventListener ?

    MDN ontransitionend 应该像我写的那样工作,到处搜索,Chrome确实支持它(事实上我记得以前使用它没有任何问题)。值得注意的是,在Chrome中,MDN页面上显示的示例对我不起作用(不显示“缩放”和“完成”文本)。

    1 回复  |  直到 7 年前
        1
  •  2
  •   V. Rubinetti    7 年前

    很显然,答案是铬是出于某种原因 does not support ontransitionend or several other transition events

    Firefox正确运行我的测试用例和MDN的测试用例。