由于某些原因,此代码可在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>
最佳答案
这行是错误的:
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;
编辑:
如果将
s
添加到最终的0
中,它将在chrome中起作用:transition: margin 0.2s ease-in-out 0.2s, transform 0.2s ease-in-out 0s;
关于javascript - CSS转换可在Safari中运行,但不能在Chrome中运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59415465/