分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

jquery 菜单展开与收缩参考脚本

发布时间:2023-09-06 02:00责任编辑:蔡小小关键词:暂无标签
/* * metismenu - v1.1.3 * Easy menu jQuery plugin for Twitter Bootstrap 3 * https://github.com/onokumus/metisMenu * * Made by Osman Nuri Okumus * Under MIT License */;(function($, window, document, undefined) { ???var pluginName = "metisMenu", ???????defaults = { ???????????toggle: true, ???????????doubleTapToGo: false ???????}; ???function Plugin(element, options) { ???????this.element = $(element); ???????this.settings = $.extend({}, defaults, options); ???????this._defaults = defaults; ???????this._name = pluginName; ???????this.init(); ???} ???Plugin.prototype = { ???????init: function() { ???????????var $this = this.element, ???????????????$toggle = this.settings.toggle, ???????????????obj = this; ???????????if (this.isIE() <= 9) { ???????????????$this.find("li.active").has("ul").children("ul").collapse("show"); ???????????????$this.find("li").not(".active").has("ul").children("ul").collapse("hide"); ???????????} else { ???????????????$this.find("li.active").has("ul").children("ul").addClass("collapse in"); ???????????????$this.find("li").not(".active").has("ul").children("ul").addClass("collapse"); ???????????} ???????????//add the "doubleTapToGo" class to active items if needed ???????????if (obj.settings.doubleTapToGo) { ???????????????$this.find("li.active").has("ul").children("a").addClass("doubleTapToGo"); ???????????} ???????????$this.find("li").has("ul").children("a").on("click" + "." + pluginName, function(e) { ???????????????e.preventDefault(); ???????????????//Do we need to enable the double tap ???????????????if (obj.settings.doubleTapToGo) { ???????????????????//if we hit a second time on the link and the href is valid, navigate to that url ???????????????????if (obj.doubleTapToGo($(this)) && $(this).attr("href") !== "#" && $(this).attr("href") !== "") { ???????????????????????e.stopPropagation(); ???????????????????????document.location = $(this).attr("href"); ???????????????????????return; ???????????????????} ???????????????} ???????????????$(this).parent("li").toggleClass("active").children("ul").collapse("toggle"); ???????????????if ($toggle) { ???????????????????$(this).parent("li").siblings().removeClass("active").children("ul.in").collapse("hide"); ???????????????} ???????????}); ???????}, ???????isIE: function() { //https://gist.github.com/padolsey/527683 ???????????var undef, ???????????????v = 3, ???????????????div = document.createElement("div"), ???????????????all = div.getElementsByTagName("i"); ???????????while ( ???????????????div.innerHTML = "<!--[if gt IE " + (++v) + "]><i></i><![endif]-->", ???????????????all[0] ???????????) { ???????????????return v > 4 ? v : undef; ???????????} ???????}, ???????//Enable the link on the second click. ???????doubleTapToGo: function(elem) { ???????????var $this = this.element; ???????????//if the class "doubleTapToGo" exists, remove it and return ???????????if (elem.hasClass("doubleTapToGo")) { ???????????????elem.removeClass("doubleTapToGo"); ???????????????return true; ???????????} ???????????//does not exists, add a new class and return false ???????????if (elem.parent().children("ul").length) { ????????????????//first remove all other class ???????????????$this.find(".doubleTapToGo").removeClass("doubleTapToGo"); ???????????????//add the class on the current element ???????????????elem.addClass("doubleTapToGo"); ???????????????return false; ???????????} ???????}, ???????remove: function() { ???????????this.element.off("." + pluginName); ???????????this.element.removeData(pluginName); ???????} ???}; ???$.fn[pluginName] = function(options) { ???????this.each(function () { ???????????var el = $(this); ???????????if (el.data(pluginName)) { ???????????????el.data(pluginName).remove(); ???????????} ???????????el.data(pluginName, new Plugin(this, options)); ???????}); ???????return this; ???};})(jQuery, window, document);

jquery 菜单展开与收缩参考脚本

原文地址:https://www.cnblogs.com/hellowzl/p/9200707.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved