我试图在我的网站上添加现代化和enquire.js,以实现一个更干净的移动实现,它只在桌面媒体查询实际应用时加载桌面内容,而不是仅仅隐藏它。然而,我的尝试已经被这样一个事实所阻碍,那就是enquire.js似乎根本不起作用。
由于加载了我的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发布于 2013-12-01 16:08:06
关闭enquire.register()方法太快了。
以下是工作代码:
enquire.register("screen and (min-width:62em)", { // <-- the bracket was here
match : function() {
alert("Matched!");
},
unmatch : function() {
alert("Unmatched!");
}
}); // Note the closing round bracket herehttps://stackoverflow.com/questions/20314068
复制相似问题