jQuery Accordion选项卡不能使用响应选项卡打开手风琴

时间:2015-08-11 07:53:17

标签: javascript jquery css jquery-ui

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

accordion view

,但箭头键不会触发display: block;而不是display: none;。已经有一段时间了,我迷失了。

以下是在标签中加载信息的代码,希望手风琴格式的平板电脑和智能手机很快就会出现:

<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。我在Vagrant上本地运行它所以无法在线显示它。 带有jQuery UI标签的实时网站,没有手风琴或响应式显示虽然是here。 没有控制台错误真的有帮助,所以希望这里有人可以告诉我我错过了什么或我如何调试它。

1 个答案:

答案 0 :(得分:0)

Jakecigar在jQuery论坛上提出了一个解决方案。代码已发布here。它允许标签在另一个较小的视口显示某个视口和手风琴,非常适合从桌面到移动设备的大小调整。

此处编写代码以在此主题中完成解决方案,并允许其他人使用:

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 -->

和init脚本

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