当前位置:首页 > 前端 > 正文内容

H5模拟微信菜单下拉菜单

Z先生8年前 (2017-03-14)前端5409

核心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

主菜单自己随意发挥吧。

分享给朋友:

相关文章

小程序二维码传参处理&UNIAPP H5传参兼容处理

首先小程序生成二维码,我这里调用的接口是:getUnlimited,我传递的参数是:invite=10001接着就是小程序中处理,如果直接扫二维码在App.vue的onLaunch中,使用decode...

简易CSS3仿照微信对话框

惯例,直接上代码HTML代码:<div class="say-box say-left"> <div class="s...

字体图标的妙用

什么是字体图标对于前端的小伙伴来说,字体应该是再熟悉不过的东西了,对于文字我们可以通过css指定文字对应的字体,字号大小,颜色。得益于css3,我们还可以在css中引入服务端字体来实现自定义字体。而字...

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

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

ColorUI色系

ColorUI色系

                          ...

uniapp开发小程序,小程序二维传参与H5、分享页面参数兼容的处理方案。

首先小程序获取二维码接口有三个,2个限制数量,一个不限制数量,但是限制生成频率(5000次/分钟)和参数长度(32位),我使用的是不限数量的接口:getUnlimited,传递的参数为:invite=...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。
请先 登录 再评论,若不是会员请先 注册