简体   繁体   English

手风琴在产品选项卡下的 Magento2 中不起作用

[英]Accordion not working in Magento2 under product tab

I am using a simple HTML+JS accordion in magento2.2.5 on the product page under a product tab named "FAQ's".我在名为“FAQ”的产品选项卡下的产品页面上的 magento2.2.5 中使用了一个简单的 HTML+JS 手风琴。 I want to show the concept of accordion for the Faq section.我想在 Faq 部分展示手风琴的概念。 But in Magento when I am using the below code it will conflict with the product tabs and they will stop working.但是在 Magento 中,当我使用下面的代码时,它会与产品选项卡冲突并且它们将停止工作。 They will not be clickable more.它们将不再是可点击的。 Please help me to resolve the issue for accordion.请帮我解决手风琴的问题。 For the time I have removed the below code from tab from Magento admin section, here is the website URL: https://uniqaya.com/staging/tinted-sunscreen.html Code: For the time I have removed the below code from tab from Magento admin section, here is the website URL: https://uniqaya.com/staging/tinted-sunscreen.html Code:

 require([ 'jquery' ], function ($) { 'use strict'; $("#element").accordion(); });
 <div id="element" class="collapsibleContainer"> <div class="collapsibleTab" data-role="collapsible"> <div data-role="trigger"> <span>Title 1</span> </div> </div> <div class="collapsibleContent" data-role="content">Content 1</div> <div class="collapsibleTab" data-role="collapsible"> <div data-role="trigger"> <span>Title 2</span> </div> </div> <div class="collapsibleContent" data-role="content">Content 2</div> <div class="collapsibleTab" data-role="collapsible"> <div data-role="trigger"> <span>Title 3</span> </div> </div> <div class="collapsibleContent" data-role="content">Content 3<br>Hello<br>World</div> </div>

Please help how I can use the same code in FAQ's tab as accordion works.请帮助我如何在 FAQ 选项卡中使用与手风琴作品相同的代码。

Regrads,研究生,

If ID of element is unique, try add accordion to require如果元素的 ID 是唯一的,请尝试将手风琴添加到要求

require([
  'jquery',
  'accordion'
], function ($) {
   $("#element").accordion();
});

I had the same problem so you can be 100% sure this works.我遇到了同样的问题,所以你可以 100% 确定这可行。

When adding Accordion into tab on product page you need to change the collapsible data-role arguments so the Tabs widget could work correctly:) Add options from Tabs widget since Accordion instantiates from Tab widget method _instantiateCollapsible :将 Accordion 添加到产品页面上的选项卡时,您需要更改可折叠数据角色 arguments 以便选项卡小部件可以正常工作:) 从选项卡小部件添加选项,因为手风琴从选项卡小部件方法_instantiateCollapsible实例化:

require([
    'jquery',
    'accordion'
], function ($) {
    $("#element").accordion({
        active: [], //optional - option from accordion
        collapsible: true, //optional - option from accordion
        collapsibleElement: "[data-role=collapsible2]", // - option from tabs
        content: "[data-role=content2]", // - option from tabs
        trigger: "[data-role=trigger2]" // - option from tabs
    });
});

and then change your HTML to:然后将您的 HTML 更改为:

...
<div class="collapsibleTab" data-role="collapsible2">
  <div data-role="trigger2">
    <span>Title 1</span>
  </div>
</div>
<div class="collapsibleContent" data-role="content2">Content 1</div>
...

You could check other options here:您可以在此处查看其他选项:

https://devdocs.magento.com/guides/v2.4/javascript-dev-guide/widgets/widget_tabs.html https://devdocs.magento.com/guides/v2.4/javascript-dev-guide/widgets/widget_tabs.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM