未定义Modernizr [英] Modernizr is not defined

查看:143
本文介绍了未定义Modernizr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将Modernizr Touch Events检测添加到了我的项目中(只保留了其余部分以使其尽可能轻便).

I've included the Modernizr Touch Events detection to my project (only left the rest out to keep it light as possible).

我用它来设置不同的Google Maps JS选项,如下所示:

I use it to set different Google Maps JS options as following:

<script>
  function initMap() {
    var myLatLng = {lat: 52.022322, lng: 4.209055};
    if( Modernizr.touchevents ) {
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 15,
            disableDefaultUI: false,
            center: myLatLng,
            scrollwheel: true,
            draggable: false,
        });

    } else {
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 15,
            disableDefaultUI: false,
            center: myLatLng,
            scrollwheel: false,
            draggable: true,
        });
    }

    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        title: 'Duijnisveld Kasconstructies',
    });
  }
</script>

我已将此脚本包含在我的page-contact.php文件中,该文件显示了我的Wordpress项目上的联系页面.

I've included this script in my page-contact.php file which displays the contact page on my Wordpress project.

每当我查看页面时,我都看不到地图,并在控制台中注意到以下错误: (index):235 Uncaught ReferenceError: Modernizr is not defined

Whenever I view the page I see no map and note the following error in my console: (index):235 Uncaught ReferenceError: Modernizr is not defined

我在这里想念什么?

谢谢大家!

推荐答案

您要在定义它的theme-min.js之前调用Modernizr.

You are calling Modernizr before theme-min.js which is where you are defining it.

您应将代码移到此行下方.

You should move your code below this line.

<script type="text/javascript" src="http://duijnisveld.wpengine.com/wp-content/themes/duijnisveld-kascontructies/scripts/min/theme-min.js?ver=4.5.3"></script>

这篇关于未定义Modernizr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆