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

H5模拟微信菜单下拉菜单

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

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

npm如何使用国内镜像源?

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

uniapp无缝滚动核心代码

1、页面代码核心代码<scroll-view class="scoll-warp">     <view&nb...

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

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

写给即将寿终正寝的Flash,即html5 Flash解决方案

写给即将寿终正寝的Flash,即html5 Flash解决方案

Adobe的Flash将于2020年12月31日正式终止。Adobe公司最近宣布,将会正式宣布停止对Flash的支持,这也变相宣布了Flash的死亡,Flash Player将于2020年12月31日...

发表评论

访客

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