在2个jquery同位素实例之间切换

时间:2013-01-09 15:37:33

标签: javascript jquery jquery-isotope

我有两个jquery-isotope实例,它们互相交换元素。这有效,但由于某种原因,我在jquery-isotopes之间得到空格。有人知道如何删除这些空格,以便正确排列同位素。我做了一个jsfiddle:http://jsfiddle.net/XEYds/

干杯!

var $container = $('#product-masonry');
var $trash = $('#trash-masonry');

$container.isotope({
    itemSelector: '.item',
});
$trash.isotope({
    itemSelector: '.item',
});

// remove item if clicked

  $container.delegate( '.remove', 'click', function(){
  var remove_id = $(this).data('item');
  $trash.isotope( 'insert',$('#' + remove_id) );
  });
  $trash.delegate( '.remove', 'click', function(){
  var remove_id = $(this).data('item');
  $container.isotope( 'insert',$('#' + remove_id) );
  });

1 个答案:

答案 0 :(得分:0)

我在jquery同位素插件中创建了两个新函数:

throwaway : function( $content, callback ) {
  // remove elements immediately from Isotope instance
  this.$allAtoms = this.$allAtoms.not( $content );
  this.$filteredAtoms = this.$filteredAtoms.not( $content );
  // remove() as a callback, for after transition / animation
  var instance = this;
  var removeContent = function() {
    $('#trash-masonry').append( $content ).isotope( 'appended', $content );
    setTimeout(function(){ $('#trash-masonry').isotope() }, 400);
    setTimeout(function(){ $('#product-masonry').isotope() }, 400);
  };

  if ( $content.filter( ':not(.' + this.options.hiddenClass + ')' ).length ) {
    // if any non-hidden content needs to be removed
    this.styleQueue.push({ $el: $content, style: this.options.hiddenStyle });
    this._sort();
    this.reLayout( removeContent );
  } else {
    // remove it now
    removeContent();
  }

},    

putback : function( $content, callback ) {
  // remove elements immediately from Isotope instance
  this.$allAtoms = this.$allAtoms.not( $content );
  this.$filteredAtoms = this.$filteredAtoms.not( $content );
  // remove() as a callback, for after transition / animation
  var instance = this;
  var removeContent = function() {
    $('#product-masonry').append( $content ).isotope( 'appended', $content );
    setTimeout(function(){ $('#trash-masonry').isotope() }, 400);
    setTimeout(function(){ $('#product-masonry').isotope() }, 400);
  };

  if ( $content.filter( ':not(.' + this.options.hiddenClass + ')' ).length ) {
    // if any non-hidden content needs to be removed
    this.styleQueue.push({ $el: $content, style: this.options.hiddenStyle });
    this._sort();
    this.reLayout( removeContent );
  } else {
    // remove it now
    removeContent();
  }

},   

$container.delegate( '.remove', 'click', function(){
    var remove_id = $(this).data('item');
    $container.isotope( 'throwaway',$('#' + remove_id) );
});
$trash.delegate( '.remove', 'click', function(){
    var remove_id = $(this).data('item');
    $trash.isotope( 'putback',$('#' + remove_id) );
});

像魅力一样工作:)