最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Modernizr is not defined - Stack Overflow

programmeradmin5浏览0评论

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

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>

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

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

What am I missing here?

Thanks guys!

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

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>

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

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

What am I missing here?

Thanks guys!

Share Improve this question asked Jun 28, 2016 at 17:36 Boris KampBoris Kamp 3381 gold badge6 silver badges20 bronze badges 2
  • 5 Are you including Modernizr before the rest of your code? – Mike Cluck Commented Jun 28, 2016 at 17:37
  • ahh shoot, that was the issue. Silly me. If you want the credit you should post an answer as you were first, otherwise I'll accept Agu V's answer – Boris Kamp Commented Jun 28, 2016 at 17:46
Add a ment  | 

1 Answer 1

Reset to default 4

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./wp-content/themes/duijnisveld-kascontructies/scripts/min/theme-min.js?ver=4.5.3"></script>
发布评论

评论列表(0)

  1. 暂无评论