'Not defined' error with Masonry javascript plugin

丶灬走出姿态 提交于 2019-12-11 03:26:30

问题


I am using Vanilla Masonry (the raw JS, non-jQuery version) as follows:

In head:

<script id="masonry" type="text/javascript" src="resources/js/masonry.js"></script>

In body:

<script>
window.onload = function() {
  var wall = new Masonry( document.getElementById('ext-component-3'), {
    columnWidth: 145
  });
};
</script>

But I keep getting:

Uncaught ReferenceError: Masonry is not defined 
Uncaught TypeError: Cannot call method 'appendChild' of undefined

Does anyone know what could be wrong in my setup?


回答1:


I looked at the masonry.js code.

You need to move the reference to the masonry file to the bottom of your page (before the closing body tag).

Or at least beneath the opening body tag.

Its trying to appendChild to the body tag which hasn't loaded in the head section.



来源:https://stackoverflow.com/questions/12738564/not-defined-error-with-masonry-javascript-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!