在站点上使用名称间隔JQuery和Isotope运行多个JQ中断浏览器调整大小功能

时间:2012-05-01 12:49:28

标签: jquery jquery-isotope

GlobalPost非常高兴能将Isotope用于我们的新业务页面。

http://www.globalpost.com/business-news

我们在Drupal上运行,因此每个页面上都运行了旧版本的jquery。

我在页面上将新JQ命名为

    <script type="text/javascript" src="/sites/all/themes/globalpost_3/js/jquery-1.7.1.min.js"></script>    
<script type='text/javascript'>
  // added to run both jquery releases on page and stop conflist with old JQ libraray
 var jQuery_1_7_1 = jQuery.noConflict(true);
</script> 
<script type="text/javascript" src="/sites/all/themes/globalpost_3/js/jquery.isotope.min.js"></script>
<script type="text/javascript" src="/sites/all/themes/globalpost_3/js/gp5_biz.js"></script>

并在最后编辑了最终版本的isitope

....eturn this}})(window,jQuery_1_7_1);

它可以正常加载并且运行正常,但是如果您调整窗口大小,则块不会重排。如果您选择过滤器或排序他们,但没有,或窗口调整大小。我看了很久你的代码,但似乎无法弄清楚导致问题的原因或解决方法。

我必须在jq库中命名空间以避免冲突,但在我做之前调整大小工作正常。我相信其他人需要使用与Isotope间隔开的JQ名称。

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

你在哪里(以及如何)初始化同位素?它可能与被引用的jquery有关。我是这样做的:

var jQuery171 = jQuery.noConflict(true);
jQuery171(function(){
    var $container = jQuery171("#container");
    $container.isotope({
        itemSelector: ".element"
    });
});

答案 1 :(得分:0)

你最后的评论让我再看看我们如何包含新的jquery库以及旧的库。我开始认为可能旧的库是这里的坏演员,因为它被包含在主批js文件(Drupal系统)中,我无法直接访问它以给它一个特定的名称空间。通过并重新命名所有原生jq函数也是完美的。

我有一个想法,基本上让旧的JQ库基本上完成所有它的工作,它们命名空间,就像这样。

<?php print $scripts; ?> <!-- all the JS for the site including old 1.3.2 JQuery -->

<script type="text/javascript">
  var jQuery132 = $.noConflict(true); // Kill the old JQ now that it is done with initializing old script
</script>

<script type="text/javascript" src="/sites/all/themes/globalpost_3/js/jquery-1.7.1.min.js"></script>    <!-- load shinny new JQuery which takes over $ and jQuery name space -->
<script type="text/javascript" src="/sites/all/themes/globalpost_3/js/jquery.isotope.min.js"></script>   <!-- non name spaced libs using default $ -->
<script type="text/javascript" src="/sites/all/themes/globalpost_3/js/gp5_biz.js"></script>  

这是有史以来最好的方式,也许不是,但它有效。

非常感谢您花费宝贵的时间帮助我完成这项工作。我按你的方式送好卡玛。