当前位置:首页 > 前端

H5模拟微信菜单下拉菜单

Z先生10年前 (2017-03-14)前端5680

核心HTML代码:

核心点:外层类“submenu-warp”

子菜单类:“submenu”

<div data-href="#mainurl" class="submenu-warp">
    <p>常见问题</p>
    <div class="submenu">
        <a href="#suburl1"><span>营销文案</span></a>
        <a href="#suburl2"><span>常见问题</span></a>
    </div>
</div>

遮蔽层:

<div id="submenu_masklayer" class="submenu_masklayer">&nbsp;</div>

CSS代码:

.submenu-warp {
	position: relative;
}

.submenu-warp .submenu {
	display: none;
	position: absolute;
	z-index: 998;
	bottom: 60px;
	left: 50%;
	width: 100px;
	margin-left: -50px;
	background: red;
	background: #e4e3e2;
	border-radius: 5px;
	-webkit-box-shadow: inset 0 0 3px #fff;
	background: url(../img/submenu_bg_2.svg#3) no-repeat center center;
	-webkit-background-size: 100%;
	background-size: 100%;
}

.submenu-warp .submenu:before {
	content: "";
	display: inline-block;
	position: absolute;
	z-index: 999;
	bottom: 0;
	left: 50%;
	width: 10px;
	height: 8px;
	background: url(../img/submenu_bg_1.svg#2) no-repeat center -55px;
	-webkit-background-size: 10px auto;
	bottom: -7px;
	margin-left: -5px;
}

.submenu-warp .submenu a {
	font-size: 12px;
	display: inline-block;
	width: 100%;
	line-height: 45px;
	text-align: center;
	background: -webkit-gradient(linear, 0 0, 100% 0, from(rgba(194, 194, 194, 0.8)), to(rgba(194, 194, 194, 0.8)), color-stop(50%, rgba(194, 194, 194, 0.8)));
	background-size: 80% 1px;
	background-repeat: no-repeat;
	background-position: center bottom;
}

.submenu_masklayer {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 180;
	background: rgba(0, 0, 0, 0);
	display: none;
}


核心JS代码:

	(function($) {
		$(document).on("click", ".submenu-warp", function() {
			var the = $(this),
				submenu, href;
			$(".submenu").hide();
			submenu = the.children(".submenu");
			if(submenu.length) {
				if($("#submenu_masklayer").css("display") == "none") {
					$("#submenu_masklayer").show();
					submenu.show();
				} else {
					$("#submenu_masklayer").hide();
					return true;
				}
			} else if(the[0].tagName != "a") {
				href = the.attr("href");
				href = href == undefined || href == null ? the.data("href") : href;
				href = href == undefined || href == null ? "" : href;
				if((href.indexOf("#") != 0 && href.indexOf("javascript:") == -1 && href != "")) {
					document.location.href = href;
					return false;
				}
				return false;
			}
		}).on("click", "#submenu_masklayer", function() {
			$(".submenu").hide();
		});
	})(jQuery);


图片资源文件:

img.zip

主菜单自己随意发挥吧。

分享给朋友:

相关文章

IE11,Chrome粘贴图片上传的JS实现方法和逻辑

核心代码如下://处理IE11,Chrome粘贴图片上传 function pasteUpload() { var file = null;…

npm如何使用国内镜像源?

通过命令配置1. 命令淘宝源npm config set registry https://registry.npmmirror.com腾讯源npm …

【原创】api接口模拟器(NodeJS版)

最近遇到一个项目,内网的APP,后端数据和前段开发属于异地,没法直接做接口数据测试。因此用NodeJs简单写了个API模拟器,只要将响应的数据放在对应目录下json.json文件中即可。请求地址全静态…

MUMU模拟器调试APP注意事项

MUMU模拟器默认ADB端口7555,所以要么修改MUMU默认端口,要么修改IDE编辑器链接端口为7555。做好这个MARK!…

npm 更新模块

npm update只能按照package.json中标注的版本号进行更新,升级后不会修改package.json中的版本号,需要自己手动修改,比较麻烦。npm-check-updates 升级插件升…

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。