0

如何通过同位素js连续检测第一个/最后一个孩子?我想删除元素之间的边距。

这是布局。` // ====================== fitRows ==================== ==

_fitRowsReset : function() {
  this.fitRows = {
    x : 0,
    y : 0,
    height : 0
  };
},

_fitRowsLayout : function( $elems ) {
  var instance = this,
      containerWidth = this.element.width(),
      props = this.fitRows;

  $elems.each( function() {
    var $this = $(this),
        atomW = $this.outerWidth(true),
        atomH = $this.outerHeight(true);

    if ( props.x !== 0 && atomW + props.x > containerWidth ) {
      // if this element cannot fit in the current row
      props.x = 0;
      props.y = props.height;
    }

    // position the atom
    instance._pushPosition( $this, props.x, props.y );

    props.height = Math.max( props.y + atomH, props.height );
    props.x += atomW;

  });
},

_fitRowsGetContainerSize : function () {
  return { height : this.fitRows.height };
},

_fitRowsResizeChanged : function() {
  return true;
},

`

4

1 回答 1

1

解决方法很简单

 // ====================== fitRows ======================

    _fitRowsReset : function() {
      this.fitRows = {
        x : 0,
        y : 0,
        height : 0
      };
    },

    _fitRowsLayout : function( $elems ) {
      var instance = this,
          containerWidth = this.element.width(),
          props = this.fitRows;

      $elems.each( function() {
        var $this = $(this),
            atomW = $this.outerWidth(true),
            atomH = $this.outerHeight(true);
        $(this).removeClass('first last');

        if (props.x == 0) {
            $(this).addClass('first');
            $(this).prev().addClass('last');

        }

        if ( props.x !== 0 && atomW + props.x > containerWidth ) {
          // if this element cannot fit in the current row
          props.x = 0;
          props.y = props.height;
          $(this).addClass('first');
          $(this).prev().addClass('last');
        }



        // position the atom
        instance._pushPosition( $this, props.x, props.y );

        props.height = Math.max( props.y + atomH, props.height );
        props.x += atomW;

      });
    },

    _fitRowsGetContainerSize : function () {
      return { height : this.fitRows.height };
    },

    _fitRowsResizeChanged : function() {
      return true;
    },
于 2013-10-16T12:55:22.960 回答