简体   繁体   English

如何在页面加载时打开两个手风琴按钮?

[英]How can I have two accordion buttons open on page load?

I'm using a product plug in for wordpress and I'm trying to make it so that the accordion menus are both open on page load. 我正在使用一个用于Wordpress的产品插件,并且正在尝试使之成为手风琴菜单都在页面加载时打开。 I'm not familiar with javascript enough to mess around with it. 我对javascript不够熟悉,无法解决。 Here is the script that is changing the accordion menus 这是更改手风琴菜单的脚本

if($wrapper.find('.mspc-accordion').size() > 0) {

        //accordion
        if( !$this.hasClass('active') ) {

            $menuItems.children('.icon').removeClass('minus').addClass('add');
            $this.children('.icon').removeClass('add').addClass('minus');

            var time = 300;
            $content.slideUp(time);
            $this.next('.mspc-content:first').delay(time).slideDown(time);

        }

    }
    else {

        //steps, tabs
        $content.find('.mspc-variations').hide();
        jQuery($this.data('target')).show();

    }

    $menuItems.removeClass('active');
    $this.addClass('active');


    evt.preventDefault();

});

I took a quick look and tried this on the MSPC Hoodie preview page. 我快速浏览了一下,并在MSPC Hoodie预览页上进行了尝试。 It works, but one caveat though, If you press on the item heading it will slide up and then down again. 它可以工作,但需要注意的是,如果按项目标题,则它将先滑后滑。

This is just a one way to give you an idea on how to get started 这只是一种让您了解入门方法的方法

jQuery(function($) {

  $(".mspc-accordion").children(".mspc-menu-item").each( function(i ,e) {

   //this will open all accordion items, it seems that if an item has the class
   //active, it wont close unless another inactive heading is clicked

        $(e).hasClass("active") ? $(e).removeClass("active") : null;
        $(e).children('.icon').removeClass('minus').addClass('add');
        $(e).children('.icon').removeClass('add').addClass('minus');
        $(e).next('.mspc-content:first').css("display","block");

   });

});

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

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