CSS转换在Safari中有效,但在Chrome中不可用

问题描述 投票:0回答:1

出于某些原因,此代码在Safari中有效,但在Chrome中不起作用。在Safari中,“汉堡包”按钮会动画显示为X。在Chrome中,它只是在两种状态之间切换。我是否遗漏了明显的东西,或者我使用的是Chrome不支持的属性?

var el = document.querySelector('.menu-button');

el.onclick = function() {
  el.classList.toggle('toggled');
}
.menu-button {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

.menu-button:hover {
  cursor: pointer;
}

.menu-button .line {
  background-color: #333;
  width: 20px;
  height: 2px;
  border-radius: 1px;
  transition: margin 0.2s ease-in-out 0.2s, transform 0.2s ease-in-out 0;
}

.menu-button .line:last-child {
  margin-top: 4px;
}

.menu-button.toggled .line {
  transition-delay: 0, 0.2s;
  transition-property: margin, transform;
}

.menu-button.toggled .line:first-child {
  margin-top: 2px;
  transform: rotate(45deg);
}

.menu-button.toggled .line:last-child {
  margin-top: -2px;
  transform: rotate(-45deg);
}
<div class="menu-button">
  <div>
    <div class="line"></div>
    <div class="line"></div>
  </div>
</div>
javascript html css css-transitions
1个回答
0
投票

此行是错误的:

transition: margin 0.2s ease-in-out 0.2s, transform 0.2s ease-in-out 0;

应该是:

transition: margin 0.2s ease-in-out, transform 0.2s ease-in-out;
© www.soinside.com 2019 - 2024. All rights reserved.