/*Add Click show To Menu*/
(function ($) {
$.fn.openActive = function (activeSel) {
activeSel = activeSel || ".active";
var c = this.attr("class");
this.find(activeSel).each(function () {
var el = $(this).parent();
while (el.attr("class") !== c) {
if (el.prop("tagName") === 'UL') {
el.show();
} else if (el.prop("tagName") === 'LI') {
el.removeClass('tree-closed');
el.addClass("tree-opened");
}
el = el.parent();
}
});
return this;
}
$.fn.treemenu = function (options) {
options = options || {};
options.delay = options.delay || 0;
options.openActive = options.openActive || false;
options.activeSelector = options.activeSelector || "";
this.find("> li").each(function () {
e = $(this);
var subtree = e.find('> ul');
var toggler = $('<span>');
toggler.addClass('toggler');
e.prepend(toggler);
if (subtree.length > 0) {
subtree.hide();
e.addClass('tree-closed');
e.find(toggler).click(function () {
var li = $(this).parent('li');
li.find('> ul').toggle(options.delay);
li.toggleClass('tree-opened');
li.toggleClass('tree-closed');
});
$(this).find('> ul').treemenu(options);
} else {
$(this).addClass('tree-empty');
}
});
if (options.openActive) {
this.openActive(options.activeSelector);
}
return this;
}
})(jQuery);
function viewport() {
var e = window, a = 'inner';
if (!('innerWidth' in window )) {
a = 'client';
e = document.documentElement || document.body;
}
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
}
jQuery(document).ready(function ($) {
var dcwidth=$(window).width();
if(dcwidth <= 1024) {
$("#nav_menu ul.menu").treemenu({}).openActive();
}
});
我将“单击显示”添加到菜单宽度树菜单jQuery。
我的jQuery使用> 1024px,并在<= 102px上添加Active treemenu。
但是当我的浏览器> 1024px时,我将尺寸调整为<= 1024px,我的jQuery不添加事件活动树菜单。如何将浏览器的大小调整为<= 1024px,添加活动树菜单,并将其大小调整为> 1024px,清除活动树菜单。
谢谢!