[英]Why I can't get hamburger menu to work properly?
I need some help here.我需要一些帮助。 I'm trying to make a hamburger menu for my website but for some reason which I can't figure out, it doesn't work.
我正在尝试为我的网站制作汉堡菜单,但由于某种我无法弄清楚的原因,它不起作用。 Here's the HTML, CSS and JavaScript code which I've written in codepen.io: https://codepen.io/TheUnrealisticProgrammer/pen/QvjvVW
这是我在 codepen.io 中编写的 HTML、CSS 和 JavaScript 代码: https ://codepen.io/TheUnrealisticProgrammer/pen/QvjvVW
Here's the JavaScript code:这是 JavaScript 代码:
$(document).ready(function(){
$('Menu').click(function(){
$(this).toggleClass('Trigger');
});
});
From the code, the first span bar should animate by rotating 135 degrees after I click on it but it's not.从代码中,第一个跨度栏应该在我点击它后旋转 135 度来设置动画,但事实并非如此。
Use Jquery and JQuery UI before using.使用前使用 Jquery 和 JQuery UI。 And
$('Menu')
Menu is not a tag but it is ID of div as per your Code Pen.而
$('Menu')
Menu 不是标签,而是根据您的 Code Pen 的 div ID。 It has to be $('#Menu')
.它必须是
$('#Menu')
。
Please do these steps.请执行这些步骤。
$('Menu')
this is jQuery as other said, you are selecting id so should be $('#Menu')
$('Menu')
正如其他人所说,这是 jQuery,您正在选择 id 所以应该是$('#Menu')
check this link for working example, fixed jQuery, js and CSS:检查此链接以获取工作示例,修复了 jQuery、js 和 CSS:
https://codepen.io/hdl881127/pen/wdKZVj https://codepen.io/hdl881127/pen/wdKZVj
fixed css:固定CSS:
#Menu{
position:relative;
margin-top:20px;
margin-left:20px;
display:block;
height:50px;
cursor: pointer;
width:50px;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
#Menu span{
position:absolute;
background:orange;
display:block;
height: 6px;
width: 100%;
border-radius:50px;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
#Menu span:nth-child(1){
top:0px;
}
#Menu span:nth-child(2){
top:18px;
}
#Menu span:nth-child(3){
top:36px;
}
#Menu.Trigger span:nth-child(1){
top: 18px;
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-o-transform: rotate(135deg);
transform: rotate(135deg);
}
#Menu.Trigger span:nth-child(2){
top: 18px;
-webkit-transform: rotate(225deg);
-moz-transform: rotate(225deg);
-o-transform: rotate(225deg);
transform: rotate(225deg);
}
#Menu.Trigger span:nth-child(3){
top: 18px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.