向上和向下滑动功能仅应在手机尺寸上显示。当我将窗口缩小到“移动”并返回到桌面大小宽度时。上下滑动功能已应用。我该如何清除? -我已经尝试过clearQueue()和stop(),但是没有真正起作用 -是否必须更改jquery的结构?
$(window).resize(function() {
// This will fire each time the window is resized:
if ($(window).width() >= 400) {
// if larger or equal
// equal Height
$("[id*='content-'], .tabs_content").height('auto');
var maxHeight = -1;
$('.tabs_content').each(function() {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$('.tabs_content').each(function() {
$(this).height(maxHeight);
});
// Control got clicked
$('.tabs_control').on('click', function() {
$("[id*='content-'], .tabs_content").clearQueue();
$('.tabs_control.active, .tabs_content.active').removeClass('active');
$(this).addClass('active');
var activeTab = $(this).attr("id").match(/[\d]/);
$("#content-" + activeTab).addClass('active');
});
} else {
// if smaller
$('.tabs_content').hide();
$('.tabs_content.active').show();
$('.tabs_control').on('click', function() {
$('.tabs_control.active').removeClass('active');
$('.tabs_content.active, .tabs_content').slideUp().removeClass("active");
$(this).addClass('active');
var activeTab = $(this).attr("id").match(/[\d]/);
$("#content-" + activeTab).clearQueue().slideDown().addClass('active');
});
}
}).resize(); // This will simulate a resize to trigger the initial run.
.tabs_container {
display: flex;
overflow: hidden;
flex-wrap: wrap;
width: 400px;
box-shadow: 0 0 1rem rgba(0, 0, 0, 0.1) !important;
}
.tabs_control {
z-index: 999;
display: inline-block;
padding: 1rem !important;
cursor: pointer;
transition: .25s ease;
transition: all;
text-align: center;
color: #8c8c8c;
border: none;
border-bottom: 1px solid #e0e0e0 !important;
border-left: 1px solid #e0e0e0 !important;
background-color: #eee;
font-size: 1.6rem;
line-height: 1.9;
max-width: 33.333333%;
}
.tabs_control:first-of-type,
.tabs_control.active:first-of-type {
border-left: none !important;
}
.tabs_control:hover {
background-color: #f2f2f2;
}
.tabs_control.active {
color: #878787;
border-bottom: none !important;
background-color: #fff;
font-weight: 700 !important;
}
.tabs_content {
display: none;
height: auto;
padding: 2rem;
background-color: #fff;
}
.tabs_content.active {
display: inline-block;
animation: fadeIn 1.5s linear;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@media (max-width: 400px) {
.tabs_control {
border-left: none !important;
}
.tabs_content {
display: none;
width: 100%;
}
.tabs_content.active {
display: inline-block !important;
animation: none;
}
/*display div order */
#tab-1 {
order: 0;
}
#content-1 {
order: 1;
}
#tab-2 {
order: 2;
}
#content-2 {
order: 3;
}
#tab-3 {
order: 4;
}
#content-3 {
order: 5;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="tabs_container">
<div id="tab-1" class="tabs_control active">Panel 1</div>
<div id="tab-2" class="tabs_control">Panel 2</div>
<div id="tab-3" class="tabs_control">Panel 3</div>
<div id="content-1" class="tabs_content active">
<p>One Content</p>
</div>
<div id="content-2" class="tabs_content">
<p>Two Content</p>
</div>
<div id="content-3" class="tabs_content">
<p>Three Content</p>
</div>
</div>