我有一个问题,因为我想用这个很酷的动画汉堡菜单按钮(“navicon1”)编码一个边栏。菜单按钮的一个很酷的动画效果用于“打开”类。如果我点击菜单按钮,我想切换功能“openNav”和“closeNav”。Javascript:使用1 Click-Listener切换2个函数
原来这就是我想要的:
- 如果我点击菜单键(navicon1)第一次 - >菜单按钮 改变为X(这工作)和执行javascript函数“openNav”
- 如果我点击菜单键(navicon1)第二次 - >菜单按钮 改变正常(这个工程)和执行javascript函数 “closeNav”
这里是我的代码:
$(document).ready(function() {
$('#navicon1,#navicon2,#navicon3,#navicon4').click(function() {
$(this).toggleClass('open');
});
});
/* Set the width of the side navigation to 250px and the left margin of the page content to 250px and add a black background color to body */
function openNav() {
document.getElementById("mySidenav").style.width = "75%";
document.getElementById("main").style.marginLeft = "75%";
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
}
/* Set the width of the side navigation to 0 and the left margin of the page content to 0, and the background color of body to white */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
document.body.style.backgroundColor = "white";
check = 0;
}
可以忽略navicon2-3,他们只对三网融合
谢谢您的帮助:)
工作完全谢谢! :) –
@DreLoo记得标记答案为回答,如果它回答你的问题。 – IMTheNachoMan