gpt4 book ai didi

javascript - jQuery Accordion 选项卡无法使用 Accordion 的响应选项卡打开

转载 作者:行者123 更新时间:2023-12-01 05:39:10 25 4
gpt4 key购买 nike

我正在使用 jQuery UI 在桌面上的选项卡中显示信息,并且已经使用了一段时间了。我已添加Responsive Tabs to Accordion在平板电脑和智能手机的 Accordion 选项卡中显示与我使网站响应相同的信息。该信息现在以 Accordion 格式显示,除了第一个选项卡之外的所有选项卡均已打开:

accordion view

但是,箭头键不会触发 display: block;,而是触发 display: none;

这是在选项卡中加载信息的代码,希望很快能以 Accordion 格式加载到平板电脑和智能手机上:

<div class="demo tabs">

<div id="tabs11" class="tabsaccordion">
<ul class="resp-tabs-list">
<li id="tab-title-overview"><a href="#tabs-1">OVERVIEW</a></li>

<li id="tab-title-accomodation"><a href="#tabs-2">ACCOMODATION</a></li>
<li id="tab-title-facilities"><a href="#tabs-3"><?php if(in_category('liveaboards')) echo "SHIP FACILITIES"; else echo "RESORT FACILITIES";?></a></li>
<li id="tab-title-diving"><a href="#tabs-4">DIVING</a></li>
<li id="tab-title-surfing"><a href="#tabs-5">SURFING</a></li>
<li id="tab-title-activities"><a href="#tabs-6">ACTIVITIES</a></li>
<li id="tab-title-special"><a href="#tabs-7">SPECIAL</a></li>
</ul>
<div class="resp-tabs-container hor_1">
<div id="tabs-1"><?php the_content(); //echo get_post_meta(get_the_ID(), "overview_value", true); ?></div>
<div id="tabs-2"><?php echo get_post_meta(get_the_ID(), "Accomodation", true); ?></div>
<div id="tabs-3"><?php echo get_post_meta(get_the_ID(), "Resort Facilities", true); ?></div>
<div id="tabs-4"><?php echo get_post_meta(get_the_ID(), "Diving", true); ?></div>
<div id="tabs-5"><?php echo get_post_meta(get_the_ID(), "Surfing", true); ?></div>
<div id="tabs-6"><?php echo get_post_meta(get_the_ID(), "Activities", true); ?></div>
<div id="tabs-7"><?php echo get_post_meta(get_the_ID(), "Special", true); ?></div>
</div>
</div>


</div><!-- End demo -->

脚本加载是使用触发的

<script type="text/javascript">
jQuery(document).ready(function() {
//Horizontal Tab
jQuery('#tabs11').easyResponsiveTabs({
type: 'default', //Types: default, vertical, accordion
width: 'auto', //auto or any width like 600px
fit: true, // 100% fit in a container
tabidentify: 'hor_1', // The tab groups identifier
activate: function(event) { // Callback function if tab is switched
var $tab = jQuery(this);
var $info = jQuery('#nested-tabInfo');
var $name = jQuery('span', $info);
$name.text($tab.text());
$info.show();
}
});
});
</script>

JavaScript 包含得很好,与 Github 上的相同,只有选项卡的 CSS 发生了一些变化,显示为 here 。没有控制台错误。我该如何调试这个?

最佳答案

Jakecigar在 jQuery 论坛上提出了一个解决方案。代码发布here 。它允许选项卡显示某个视口(viewport),并在另一个较小的视口(viewport)显示 Accordion ,这非常适合从桌面调整到移动设备的大小。

在此处编写代码以使解决方案在此线程中完成并供其他人使用:

JavaScript

! function($) {
$.fn.tabsOrAccordion = function(e, i, t) {
return this.each(function() {
function n(e) {
e.matches ? r.is(".ui-accordion") && (o.active = r.accordion("option", "active"), r.accordion("destroy").children("h3").remove(), a.clone().prependTo(r), r.tabs(o)) : r.is(".ui-tabs") && (c.active = r.tabs("option", "active"), r.tabs("destroy").children("ul").remove(), r.children().each(function(e) {
$("<h3>", {
text: a.children().eq(e).text()
}).insertBefore(this)
}), r.accordion(c))
}
var c = $.extend({}, t),
o = $.extend({}, i),
a = $(this).children("ul").clone(),
r = $(this).tabs(o);
if ("matchMedia" in window) {
var d = matchMedia(e);
d.addListener(n), n(d)
}
})
}
}(jQuery);

html

<div id="tabs">
<ul>
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
</ul>
<div id="tabs-1">
<h2>Content heading 1</h2>
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
</div>
<div id="tabs-2">
<h2>Content heading 2</h2>
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tabs-3">
<h2>Content heading 3</h2>
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
</div>

在论坛主题中,我还提到了我的 WordPress 解决方案。

HTML,包括 WordPress PHP

<div class="demo tabs">


<div id="tabs11" class="tabsaccordion">

<ul class="resp-tabs-list">

<li id="tab-title-overview"><a href="#tabs-1">ONE</a></li>


<li id="tab-title-accomodation"><a href="#tabs-2">TO</a></li>

<li id="tab-title-facilities"><a href="#tabs-3"><?php if(in_category('live')) echo "SHIP FACILITIES"; else echo "THREE";?></a></li>

<li id="tab-title-d"><a href="#tabs-4">FOUR</a></li>

<li id="tab-title-s"><a href="#tabs-5">FIVE</a></li>

<li id="tab-title-a"><a href="#tabs-6">SIX</a></li>

<li id="tab-title-s"><a href="#tabs-7">SEVEN</a></li>

</ul>

<div id="tabs-1"><?php the_content(); //echo get_post_meta(get_the_ID(), "overview_value", true); ?></div>

<div id="tabs-2"><?php echo get_post_meta(get_the_ID(), "ID", true);
?></div>
<div id="tabs-3"><?php echo get_post_meta(get_the_ID(), "ID 2", true);
?></div>
<div id="tabs-4"><?php echo get_post_meta(get_the_ID(), "ID 3", true);
?></div>
<div id="tabs-5"><?php echo get_post_meta(get_the_ID(), "ID 4", true);
?></div>
<div id="tabs-6"><?php echo get_post_meta(get_the_ID(), "ID 5", true);
?></div>
<div id="tabs-7"><?php echo get_post_meta(get_the_ID(), "ID 6", true);
?></div>

</div>



</div><!-- End demo -->

以及初始化脚本

jQuery(function() {
jQuery( "#tabs11" ).tabsOrAccordion("(min-width: 1000px)",{},{
heightStyle:"content",
collapsible: true
})
});

关于javascript - jQuery Accordion 选项卡无法使用 Accordion 的响应选项卡打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31936137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com