【发布时间】:2021-06-30 16:26:18
【问题描述】:
我正在尝试实现 Will Myers 的教程 https://www.youtube.com/watch?v=4_fvE8mO1ic&t=26s
在方形空间 7.1
您可以在此处查看我的实时页面。 https://www.thesquaresandbox.com/tabbed-sections 当我单击选项卡按钮时,会出现正确的部分,但其他两个部分应该被隐藏,但它们不是。 TIA
<script>
function tabOneClick() {
$('button.tab-btn:nth-of-type(1)').addClass("active");
$('button.tab-btn:nth-of-type(2)').removeClass("active");
$('button.tab-btn:nth-of-type(3)').removeClass("active");
$('[data-section-id="6069af192a871859f3dddfc3"]').addClass("tab-section-show");
$('[data-section-id="6069af0fd446556b94c10177"]').removeClass("tab-section-show");
$('[data-section-id="6069bad471b2824d888bdf66"]').removeClass("tab-section-show");
}
function tabTwoClick() {
$('button.tab-btn:nth-of-type(1)').removeClass("active");
$('button.tab-btn:nth-of-type(2)').addClass("active");
$('button.tab-btn:nth-of-type(3)').removeClass("active");
$('[data-section-id="6069af192a871859f3dddfc3"]').removeClass("tab-section-show");
$('[data-section-id="6069af0fd446556b94c10177"]').addClass("tab-section-show");
$('[data-section-id="6069bad471b2824d888bdf66"]').removeClass("tab-section-show");
}
function tabThreeClick() {
$('button.tab-btn:nth-of-type(1)').removeClass("active");
$('button.tab-btn:nth-of-type(2)').removeClass("active");
$('button.tab-btn:nth-of-type(3)').addClass("active");
$('[data-section-id="6069af192a871859f3dddfc3"]').removeClass("tab-section-show");
$('[data-section-id="6069af0fd446556b94c10177"]').removeClass("tab-section-show");
$('[data-section-id="6069bad471b2824d888bdf66"]').addClass("tab-section-show");
}
$(function() {
$('[data-section-id="6069af192a871859f3dddfc3"]').addClass("tab-section-hide");
$('[data-section-id="6069af0fd446556b94c10177"]').addClass("tab-section-hide");
$('[data-section-id="6069bad471b2824d888bdf66"]').addClass("tab-section-hide");
tabOneClick();
});
</script>
.tabs-container{
transform:translateY(100%);
width:100% !important;
text-align:center;
border-bottom: 1px solid #999;
overflow: auto;
overflow-x:auto;
white-space: nowrap;
z-index:99;
}
.tab-btn{
max-width:150px;
display: inline-block;
border-radius:3px 3px 0 0;
border:1px solid #999;
padding: 12px 18px;
font-size:1.2em;
background:white;
margin-bottom:none !important;
border:none !important;
&:not(:first-of-type){
margin-left:10px;
}
}
.tab-btn.active{
background:lightblue;
}
.tab-section-hide{
display:none;
}
.tab-section-show{
display:block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<div class="tabs-container">
<button class="tab-btn" id="tab-1" onclick="tabOneClick()">
About
</button>
<button class="tab-btn" id="tab-2" onclick="tabTwoClick()">
Gallery
</button>
<button class="tab-btn" id="tab-3" onclick="tabThreeClick()">
Contact
</button>
</div>
【问题讨论】:
标签: jquery css squarespace