簡體   English   中英

enquire.js javascript無法執行(enquire.js,Modernizr,jQuery)

[英]enquire.js javascript doesn't execute (enquire.js, Modernizr, jQuery)

我正在嘗試將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

您太快關閉了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 here

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM