0

我有 2 个 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) );
  });
4

1 回答 1

0

我在 jquery isotope 插件中创建了 2 个新功能:

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) );
});

奇迹般有效 :)

于 2013-01-10T22:49:01.797 回答