javascript - 使用 JQuery 显示子菜单

标签 javascript jquery html

我需要一些帮助,使子菜单在页面加载后2秒内出现,而不是在用户单击它时出现。我正在使用JQuery。该文件是网站的核心。我需要它保持打开状态。

这是我目前的代码,我尝试更改 on.Click 事件,但没有成功。

handleSidenarAndContentHeight(); 函数在子菜单出现后调整菜单项的大小。

jQuery('.page-sidebar li > a').on('click', function (e) {
    if ($(this).next().hasClass('sub-menu') === false) {
        return;
    }
    var parent = $(this).parent().parent();
    parent.children('li.open').children('a').children('.arrow').removeClass('open');
    parent.children('li.open').children('a').children('.arrow').removeClass('active');
    parent.children('li.open').children('.sub-menu').slideUp(350);
    parent.children('li').removeClass('open');
    parent.children('li').removeClass('active');

    var sub = jQuery(this).next();
    if (sub.is(":visible")) {
        jQuery('.arrow', jQuery(this)).removeClass("open");
        jQuery(this).parent().removeClass("active");
        sub.slideUp(350, function () {
            handleSidenarAndContentHeight();
        });
    } else {
        jQuery('.arrow', jQuery(this)).addClass("open");
        jQuery(this).parent().addClass("open");
        sub.slideDown(350, function () {
            handleSidenarAndContentHeight();
        });
    }

    e.preventDefault();
});

最佳答案

使用 2 秒超时应该可以解决问题!

jQuery(document).ready(function(){
  // Open Parent here

  setTimeout(function(){
    // Open Child here
  }, 2000)
});

关于javascript - 使用 JQuery 显示子菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42550860/

相关文章:

php - 实现弹出窗口

javascript - Ionic 2 从子页面修改 app.js 中的变量

javascript - testcafe 基于浏览器运行不同的测试

jquery - 无法设置未定义的属性 'url'

javascript - 如何在 jquery 创建后动态更改 div 的颜色?

jquery - 正确对齐/居中 bootstrap3 图像

javascript - 使用 jQuery 动态添加元素的 Clipboard.js 实现

javascript - 具有绝对位置的CSS旋转

javascript - 有没有办法计算有多少人访问了我的网站?

html - 在 iframe 中滚动时修复屏幕顶部的 div