简体   繁体   English

如何使用jQuery打开和关闭div

[英]How to use jQuery to switch divs on and off

Okay so I am looking at this website, http://codetunnel.net/ , and I saw that it only used one page, but jQuery was used to display different divs, therefore making it feel like a multipage website. 好的,所以我看的是这个网站http://codetunnel.net/ ,我看到它只使用一页,但是使用jQuery来显示不同的div,因此使其看起来像是一个多页网站。 I tried using the jQuery in my codepen, but it never worked. 我尝试在我的Codepen中使用jQuery,但从未成功。 Can someone help me understand how the jQuery works, and how I can implement it into my own sites? 有人可以帮助我了解 jQuery的工作原理以及如何在自己的网站中实现它吗? The jQuery looks like this: jQuery看起来像这样:

 $(function(){ $("#nav-home").click(function(){ $("#home").show(); $("#projects").hide(); $("#contact").hide(); $(".selected").removeClass("selected"); $("#nav-home").addClass("selected"); }); $("#nav-projects").click(function(){ $("#home").hide(); $("#projects").show(); $("#contact").hide(); $(".selected").removeClass("selected"); $("#nav-projects").addClass("selected"); }); $("#nav-contact").click(function(){ $("#home").hide(); $("#projects").hide(); $("#contact").show(); $(".selected").removeClass("selected"); $("#nav-contact").addClass("selected"); }); }); 

https://codepen.io/orchtechnerd/pen/dRzGZV // my codepen https://codepen.io/orchtechnerd/pen/dRzGZV //我的代码笔

Actually, your code works. 实际上,您的代码有效。 Unfortunately, the visible div is covered by the #nav. 不幸的是,可见的div被#nav覆盖。 So the only thing you should do is add a "padding-top: 4em" style to the body. 因此,您唯一要做的就是在主体上添加“ padding-top:4em”样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM