我需要一些帮助,使子菜单在页面加载后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/