我正在尝试在WordPress网站上创建一个垂直选项卡式部分。我已经获得了这段代码,但是我无法使按钮正常工作。请帮助我解决此问题。
我在https://codepen.io/hilotacker/pen/dXpeYg/处找到了类似的示例,但就我而言,我使用的是CSS而不是scss。我也将$更改为WordPress的jQuery,因为它带有jquery库。
我无法确定我在做什么错。请帮忙。
<body>
<div class="wrapper">
<header>
<h1>Tabbed Content</h1>
</header>
<nav>
<ul>
<li class="gnav1">One</li>
<li class="gnav2">Two</li>
<li class="gnav3">Three</li>
<li class="gnav4">Four</li>
</ul>
</nav>
<div class="contents" id="contents">
<div class="container">
<article id="page1" class="show top">
<section>
<h1>One</h1>
<p>Number one.</p>
</section>
</article>
<article id="page2">
<section>
<h1>Two</h1>
<p>Number two.</p>
</section>
</article>
<article id="page3">
<section>
<h1>Three</h1>
<p>Number Three</p>
</section>
</article>
<article id="page4">
<section>
<h1>Four</h1>
<p>Number four</p>
</section>
</article>
<article id="page5">
<section>
<h1>Tab5 Title</h1>
<p>This is tab five</p>
</section>
</article>
</div>
</div>
</div>
<style>
body, html {
height: 100%;
padding: 1.5rem;
box-sizing: border-box;
font-family: 'Cairo', sans-serif;
}
.wrapper {
width: 100%;
height: 100%;
margin: auto;
border-radius: 8px;
background: #f0f0f0;
position: relative;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}
header h1 {
background: #f0f0f0;
color: #555;
padding: 1rem;
border-radius: 8px 8px 0 0;
box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.3);
position: relative;
z-index: 8;
}
nav {
width: 100%;
background: linear-gradient(135deg, #fcc274 0%, #eb48a1 100%);
}
@media (min-width: 769px) {
nav {
float: left;
width: 96px;
height: calc(100% - 3rem);
border-radius: 0 0 0 8px;
}
}
nav ul {
display: flex;
}
@media (min-width: 769px) {
nav ul {
display: block;
}
}
nav li {
line-height: 3;
padding: 0 1rem;
border-right: 1px solid #f0f0f0;
cursor: pointer;
color: #fff;
box-sizing: border-box;
}
@media (min-width: 769px) {
nav li {
border-bottom: 1px solid #f0f0f0;
border-right: none;
}
}
nav li.hover {
background: rgba(255, 255, 255, 0.2);
}
nav li.pressed {
background: rgba(255, 255, 255, 0.7);
}
nav li.currentPage {
background: rgba(255, 255, 255, 0.5);
}
#contents {
box-sizing: border-box;
position: absolute;
height: calc(100% - 6rem);
width: 100%;
top: 6rem;
left: 0;
border-radius: 0 0 8px 0;
overflow: hidden;
background: linear-gradient(135deg, #1c1a30 0%, #38335d 100%);
}
@media (min-width: 769px) {
#contents {
height: calc(100% - 3rem);
width: calc(100% - 6rem);
top: 3rem;
left: 96px;
}
}
article {
position: absolute;
height: 100%;
width: 100%;
padding: 2rem;
box-sizing: border-box;
background: linear-gradient(135deg, #38335d 0%, #1c1a30 100%);
top: 0;
left: -100%;
}
article.hide {
transition: left 0s 0.5s;
}
article:nth-of-type(1) {
z-index: 5;
}
article:nth-of-type(2) {
z-index: 4;
}
article:nth-of-type(3) {
z-index: 3;
}
article:nth-of-type(4) {
z-index: 2;
}
article:nth-of-type(5) {
z-index: 1;
}
article.show {
transition: left 0.5s;
left: 0;
z-index: 6;
}
article section {
width: 100%;
color: #fff;
}
article section h1 {
font-size: 1.5rem;
margin: 0 0 2rem 0;
}
</style>
<script>
jQuery(document).ready(function(){
var item_num = jQuery('nav li').length + 1;
var btn_state = true;
jQuery('nav li').hover(function(){
jQuery(this).addClass('hover');
},function(){
jQuery(this).removeClass('hover');
});
jQuery('nav li').on('click',function(){
if(btn_state){
btn_state = !btn_state;
jQuery('nav li').removeClass('currentPage');
jQuery(this).addClass('currentPage');
var i = jQuery('nav li').index(this);
jQuery('article').removeClass('show');
jQuery('article').addClass('hide');
jQuery('article').eq(i).addClass('show');
setTimeout(function(){
btn_state = !btn_state;
},500);
}
});
});
</script>
</body>
</html>