H5模拟微信菜单下拉菜单
核心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"> </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);图片资源文件:
主菜单自己随意发挥吧。



