2

我试图在同一个站点上使用 jQuery masonry 3 次。每个代码块独立工作,但是当尝试同时使用所有 3 个代码块时,只有最后一个代码块有效。我怎样才能将这些结合起来工作,同时保持不同的值和选择器每个都有?

/** First Instance **/
    var $container = $('.smallcolwrap');
        $container.imagesLoaded(function(){
          $container.masonry({
            itemSelector : '.smallcol',
            columnWidth: function( containerWidth ) {
                return containerWidth / 3; },
            isAnimated: true
          });
        });

    /** Second Instance **/
    var $container = $('.slickr-flickr-gallery');
        $container.imagesLoaded(function(){
          $container.masonry({
            itemSelector : 'li',
            columnWidth: 160,
            isAnimated: true
          });
        });

    /** Third Instance **/  
    var $container = $('.navigationHome');
        $container.imagesLoaded(function(){
          $container.masonry({
            itemSelector : 'li',
            columnWidth: function( containerWidth ) {
                return containerWidth / 2; },
            isAnimated: true,
                animationOptions: {
                duration: 250,
                easing: 'linear',
                queue: false
                }
          });
        }); 
4

1 回答 1

2

哇,谢谢凯文。我不是 JS 专家,但这很容易。这就是盯着这个看太久后会发生的事情。

/** First Instance **/
var $container = $('.smallcolwrap');
    $container.imagesLoaded(function(){
      $container.masonry({
        itemSelector : '.smallcol',
        columnWidth: function( containerWidth ) {
            return containerWidth / 3; },
        isAnimated: true
      });
    });

/** Second Instance **/
var $container1 = $('.slickr-flickr-gallery');
    $container1.imagesLoaded(function(){
      $container1.masonry({
        itemSelector : 'li',
        columnWidth: 160,
        isAnimated: true
      });
    });

/** Third Instance **/  
var $container2 = $('.navigationHome');
    $container2.imagesLoaded(function(){
      $container2.masonry({
        itemSelector : 'li',
        columnWidth: function( containerWidth ) {
            return containerWidth / 2; },
        isAnimated: true,
            animationOptions: {
            duration: 250,
            easing: 'linear',
            queue: false
            }
      });
    }); 
于 2012-06-09T02:15:49.733 回答