我正在尝试将 Modernizr 和 enquire.js 添加到我的网站,以实现更简洁的移动实现,该实现仅在桌面媒体查询实际应用时才加载桌面内容,而不仅仅是隐藏它。然而,我的尝试已经被 enquire.js 似乎根本不起作用的事实所阻止。
似乎我已经设法让 Modernizr 正常运行,因为我的 unrealsp.js 已加载(代码的下拉菜单相关部分工作正常),但无论我做什么,enquire.js 部分中的代码都不会执行. 任何帮助将不胜感激。
我的 HTML 代码:
<head>
<!-- [...] -->
<!--[if lt IE 9]>
<script src="includes/html5shiv.js"></script>
<![endif]-->
<script src="includes/js/modernizr.min.js"></script>
</head>
<!-- [...] -->
<script type="text/javascript">
Modernizr.load([
{
test: window.matchMedia,
nope: "includes/js/media.match.min.js"
},
"//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js",
"includes/js/enquire.min.js",
"includes/js/unrealsp.js"
]);
我的“unrealsp.js”代码:
$(document).ready(function(){
$("ul.topmenu li a").click(function(event) {
var element = $(this).parent().find("ul.submenu");
//Following events are applied to the submenu itself (moving submenu up and down)
$(this).parent().parent().find("ul.submenu").not(element).slideUp();
element.slideToggle(); //Drop down the submenu on click }
});
enquire.register("screen and (min-width:62em)"), {
match : function() {
alert("Matched!");
},
unmatch : function() {
alert("Unmatched!");
}
}
});
enquire.min.js 中错误的控制台输出(我使用的是最新的):
Uncaught TypeError: Cannot read property 'deferSetup' of undefined enquire.min.js:7
s enquire.min.js:7
o.addHandler enquire.min.js:7
(anonymous function) enquire.min.js:7
i enquire.min.js:7
r.register enquire.min.js:7
(anonymous function) unrealsp.js:9
c jquery.js:7341
p.fireWith jquery.js:7403
b.extend.ready jquery.js:6875
H jquery.js:6601