简体   繁体   English

包含错误的简短JQuery代码-有什么问题?

[英]Short JQuery code containing the error - what is wrong?

I am trying to use a script to get the masonry effect. 我正在尝试使用脚本来获得砌体效果。 I'm using script I've found on https://masonry.desandro.com/v2/docs/intro.html 我正在使用在https://masonry.desandro.com/v2/docs/intro.html上找到的脚本

$(function() {
  $("#new").masonry({
    itemSelector: ".element",
    columnWidth: function(containerWidth) {
      return containerWidth / 2;
    }
  });
});

This is a small part of my site but it turns out that the script has some error because the other scripts in my scripts file stop working. 这只是我网站的一小部分,但事实证明该脚本有一些错误,因为我的脚本文件中的其他脚本停止工作。 If I remove this piece of code everything goes back to normal. 如果删除这段代码,一切将恢复正常。

I don't know if it is important but my file (scripts.js) looks something like this: 我不知道它是否重要,但是我的文件(scripts.js)看起来像这样:

/** Function 1 **/
 $(function() {
 ...

/** Function 2 **/
 $(function() {
 ...

/** Function 3 **/
 $(function() {
 ...

I was trying to use some JS validators but it didn't help. 我试图使用一些JS验证器,但没有帮助。

From the look of your sample containerWidth is not defined. 从您的示例外观来看,containerWidth未定义。

Edit: the comments are correct ignore this, it's wrong 编辑:评论正确无视此,这是错误的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM