【问题标题】:Joomla 3.2 breaking masonry functionJoomla 3.2 打破砌体功能
【发布时间】:2014-02-13 09:50:26
【问题描述】:

我设置了一个在 Joomla 3.1 上运行的网站,并且我正在使用一个完美运行的砌体脚本:

    // Masonry for boxes
    function adjustments() {
        $('#position-2').masonry({
            singleMode: false,
            columnWidth: 272,
            resizeable: true,
            itemSelector: '.newsflash-item',
             isAnimated: true
        });
    }

我首先加载在 masonry.desandro.com 上找到的 JS 文件 jquery.masonry.min.js 以及来自 JQuery 存储库的最新 jquery.min.js 文件。

在我安装了 Joomla 的最新更新并将其从 3.1 升级到 3.2 之前,这一直运行良好。现在,无论我如何尝试调用或定位 JS 文件,砌体功能都将不起作用。我只得到这个错误:

Uncaught TypeError: Cannot call method 'masonry' of null

此时,就像树对伐木工人说的那样,我被难住了。还有其他人遇到此问题和/或有任何解决方法的想法吗?

【问题讨论】:

    标签: joomla jquery-masonry joomla3.2 typeerror


    【解决方案1】:

    Joomla 3.2 release 更新了一些 jQuery elements,删除了更多 MooTools 依赖项并看到了 com_ajax 的引入,因此您可能遇到了冲突。

    更具体地说,您可能遇到了 JQuery 冲突,需要使用 noconflict(),您可以阅读如何使用 adapt your script to use jQuery in noconflict() mode here

    这样简单的事情可能会奏效:

    // Masonry for boxes
    function adjustments() {
        var $j = jQuery.noConflict();
        $j('#position-2').masonry({
            singleMode: false,
            columnWidth: 272,
            resizeable: true,
            itemSelector: '.newsflash-item',
             isAnimated: true
        });
    }
    

    【讨论】:

    • 做到了,谢谢!我添加了一个无冲突脚本,但不在函数本身内。谢谢你!这是我在墙上撞了好几个小时的问题之一。
    【解决方案2】:

    与 cppl 的回答类似,指定您希望基本上确保您的脚本使用 JQuery,您可以这样做:

    function adjustments() {
            JQuery('#position-2').masonry({
                singleMode: false,
                columnWidth: 272,
                resizeable: true,
                itemSelector: '.newsflash-item',
                 isAnimated: true
            });
        }
    

    这确保了 JS 选择是使用 jQuery 而不是 Mootools 或任何其他 JS 完成的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      • 2012-09-21
      • 2018-11-06
      • 2019-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多