使用Masonry javascript插件“未定义”错误 [英] 'Not defined' error with Masonry javascript plugin

查看:80
本文介绍了使用Masonry javascript插件“未定义”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Vanilla Masonry (原始JS,非jQuery版本) )如下:

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

在头部:

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

在正文中:

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

但我一直得到:

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

有人知道我的设置有什么问题吗?

Does anyone know what could be wrong in my setup?

推荐答案

我看着砖石结构.js代码。

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.

它试图将appendChild附加到未添加到head部分的body标记中。

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

这篇关于使用Masonry javascript插件“未定义”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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