Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

javascript - 添加和删??除切换打开和关闭全屏导航的类(add and remove classes that toggle open and close full screen navigation)

I'm currently working on a full screen navigation menu that opens when I click the hamburger icon.(我目前正在使用全屏导航菜单,当我单击汉堡包图标时会打开。)

Right now I am able to toggle the navigation by adding a class called "open" that triggers when I click on the menu.(现在,我可以通过添加一个名为“ open”的类来切换导航,该类在单击菜单时触发。) But I am stuck when it comes to closing it.(但是在关闭它时,我陷入了困境。) Could you review my code and let me know what I'm missing?(您能否查看我的代码并让我知道我所缺少的内容?) $(document).ready(function() { $('#menu').on('click', function() { $('.overlay').addClass('open'); $('#menu').removeClass('open-menu'); $('#menu').addClass('close-menu'); }); $('.#menu').on('click', function() { $('.overlay').removeClass('open'); $('#menu').addClass('open-menu'); $('#menu').removeClass('close-menu'); }); });   ask by Oscar Diaz translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

use toogle function for this like(为此使用toogle函数)

$( "#target" ).toggle(function() { alert( "First handler for .toggle() called." ); }, function() { alert( "Second handler for .toggle() called." ); });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...