jQuery.Mason在jQuery砌体中是未定义的

时间:2012-11-21 08:33:07

标签: jquery jquery-masonry

我使用了jQuery砌体脚本。在那个剧本中,我使用了Corner邮票。我的代码就像轰鸣声。

  jQuery.Mason.prototype.resize = function() {
    this._getColumns();
    this._reLayout();
  };

  jQuery.Mason.prototype._reLayout = function( callback ) {
    var freeCols = this.cols;
    if ( this.options.cornerStampSelector ) {

      var containerWidth = this.cols * this.columnWidth - this.options.gutterWidth;
      this.element.css({ width: containerWidth });

      var $cornerStamp = this.element.find( this.options.cornerStampSelector ),
          cornerStampX = $cornerStamp.offset().left - 
            ( this.element.offset().left + this.offset.x + parseInt($cornerStamp.css('marginLeft')) );
      freeCols = Math.floor( cornerStampX / this.columnWidth );
    }
    // reset columns
    var i = this.cols;
    this.colYs = [];
    while (i--) {
      this.colYs.push( this.offset.y );
    }

    for ( i = freeCols; i < this.cols; i++ ) {
      this.colYs[i] = this.offset.y + $cornerStamp.outerHeight(true);
    }

    // apply layout logic to all bricks
    this.layout( this.$bricks, callback );
  };

但现在它显示“jQuery.Mason未定义”。我的代码有什么问题请建议我。

1 个答案:

答案 0 :(得分:0)

我的代码遇到了类似的问题。我按照masonry.desandro.com的说明进行操作,但脚本无法使用jQuery 1.8.3。

我将$ .Mason.prototype._reLayout函数更改为以下内容:

$.Mason.prototype._reLayout = function(callback) {
var freeCols = this.cols;
if (this.options.cornerStampSelector) {
  //jQuery Selector
  var cornerStamp = $(this.options.cornerStampSelector);
  var cornerStampX = cornerStamp.offset().left - (this.element.offset().left + this.offset.x + parseInt(cornerStamp.css('marginLeft')));
  var freeCols = Math.floor(cornerStampX / this.columnWidth);
}
//Reset columns
var i = this.cols;
this.colYs = [];
while (i--) {
  this.colYs.push( this.offset.y );
}
for (i = freeCols; i < this.cols; i++ ) {
  this.colYs[i] = this.offset.y + cornerStamp.outerHeight(true);
}
//Apply layout logic to all bricks
this.layout(this.$bricks, callback); };

假设您拥有类似于砌体示例中设置的css,代码可以正常工作!