;(function ($) { var lm = function (ele, options) { this.$element = ele this.defaults = {} this.settings = $.extend({}, this.defaults, options) } lm.prototype = { menu : function () { var _this = this.$element var li_height = _this.find('.f2 li').height() + parseint(_this.find('.f2 li').css('padding-top')) + parseint(_this.find('.f2 li').css('padding-bottom')) $('.menu-dark-backdrop').on('click', function () { if (_this.hasclass('menu-open')) { _this.removeclass('menu-open') $('.menu-dark-backdrop').removeclass('in').off() $('body').css("overflow", "auto") _this.find('li').removeclass('open').off().find('div').css({ "height": 0 }) _this.scrolltop(0) } else { _this.addclass('menu-open') $('.menu-dark-backdrop').addclass('in') $('body').css("overflow", "hidden") } }) _this.find('li').on('click',function (e) { if ($(this).hasclass('open')) { $(this).removeclass('open').find('li').removeclass('open') } else { $(this).addclass('open').siblings().removeclass('open').find('li').removeclass('open') } /*li��������չʾ*/ var _index = $(this).children().eq(1).children().children().length if (!$(this).hasclass('open')) { $(this).children().eq(1).css({ "height": 0 }) $(this).find('div').css({ "height": 0 }) if ($(this).parent().parent().hasclass("f2")) { var _parentheight = $(this).parent().children().length * li_height $(this).parent().parent().css({ "height": _parentheight + "px" }) } } else { var _divheight = _index * li_height $(this).children().eq(1).css({ "height": _divheight + "px" }) if ($(this).parent().parent().hasclass("f2")) { var _parentheight = $(this).parent().children().length * li_height _parentheight = parseint(_parentheight) + _divheight $(this).parent().parent().css({ "height": _parentheight + "px" }) } $(this).siblings().find('div').css({ "height": 0 }) } if(e && e.stoppropagation) { e.stoppropagation() } else { window.event.cancelbubble = true } e.preventdefault() }) }, init: function () { var $btn = $(this.settings.triggerbtn) var obj = this $btn.click(function () { if (!$('body').find('div').hasclass('menu-dark-backdrop')) { $('body').append('') } if (obj.$element.hasclass('menu-open')) { obj.$element.removeclass('menu-open') $('.menu-dark-backdrop').removeclass('in').off() $('body').css("overflow", "auto") obj.$element.find('li').removeclass('open').off().find('div').css({ "height": 0 }) obj.$element.scrolltop(0) } else { obj.$element.addclass('menu-open') $('.menu-dark-backdrop').addclass('in') obj.menu() } }) } } $.fn.leftmenu = function (options) { var lm = new lm(this, options) lm.$element.addclass('leftmenu') return lm } }(jquery))