https://codepen.io/anon/pen/QNqgMo
为什么顶线没有动画?有人能告诉我代码中有什么问题吗?
由于
#hamburger-icon.active .line-1 {
transform: translateY(25px) translateX(0) rotate(45deg);
-webkit-transform: translateY(25px) translateX(0) rotate(45deg);
-moz-transform: translateY(25px) translateX(0) rotate(45deg);
}
#hamburger-icon.active .line-2 {
opacity: 0;
}
#hamburger-icon.active .line-3 {
transform: translateY(-10px) translateX(0) rotate(-45deg);
-webkit-transform: translateY(-10px) translateX(0) rotate(-45deg);
-moz-transform: translateY(-10px) translateX(0) rotate(-45deg);
答案 0 :(得分:4)
你走了:
#hamburger-icon {
position: absolute;
top: 25px;
left: 25px;
height: 27px;
width: 50px;
cursor: pointer;
display: block;
}
#hamburger-icon .line {
position: absolute;
display: block;
background: #c8c8c8;
width: 22px;
height: 2px;
left: 0;
transition: all 0.4s;
-webkit-transition: all 0.4s;
-moz-transition: all 0.4s;
}
#hamburger-icon .line.line-1 {
top: 0px;
}
#hamburger-icon .line.line-2 {
top: 7px;
}
#hamburger-icon .line.line-3 {
top: 14px;
}
#hamburger-icon.active .line-1 {
transform: translateY(-10px) translateX(0) rotate(45deg);
-webkit-transform: translateY(-10px) translateX(0) rotate(45deg);
-moz-transform: translateY(-10px) translateX(0) rotate(45deg);
}
#hamburger-icon.active .line-2 {
opacity: 0;
}
#hamburger-icon.active .line-3 {
transform: translateY(-10px) translateX(0) rotate(-45deg);
-webkit-transform: translateY(-10px) translateX(0) rotate(-45deg);
-moz-transform: translateY(-10px) translateX(0) rotate(-45deg);
}
您为代码添加了一个括号,因此它无法正常工作
答案 1 :(得分:2)
之后还有一个额外的括号
#hamburger-icon .line.line-3 {
top: 14px;
}
只需删除它,您的代码就可以正常运行
#hamburger-icon {
position: absolute;
top: 25px;
left: 25px;
height: 27px;
width: 50px;
cursor: pointer;
display: block;
}
#hamburger-icon .line {
position: absolute;
display: block;
background: #c8c8c8;
width: 22px;
height: 2px;
left: 0;
transition: all 0.4s;
-webkit-transition: all 0.4s;
-moz-transition: all 0.4s;
}
#hamburger-icon .line.line-1 {
top: 0px;
}
#hamburger-icon .line.line-2 {
top: 7px;
}
#hamburger-icon .line.line-3 {
top: 14px;
}
#hamburger-icon.active .line-1 {
transform: translateY(25px) translateX(0) rotate(45deg);
-webkit-transform: translateY(25px) translateX(0) rotate(45deg);
-moz-transform: translateY(25px) translateX(0) rotate(45deg);
}
#hamburger-icon.active .line-2 {
opacity: 0;
}
#hamburger-icon.active .line-3 {
transform: translateY(-10px) translateX(0) rotate(-45deg);
-webkit-transform: translateY(-10px) translateX(0) rotate(-45deg);
-moz-transform: translateY(-10px) translateX(0) rotate(-45deg);
}