找到回调函数的位置

发布于 2025-01-03 09:51:39 字数 1816 浏览 0 评论 0原文

我找不到可以在哪里放置自己的代码来调整大小和重新定位。我需要找到在哪里插入回调,这是我应该查看的唯一位,我只是找不到在调整大小时插入回调函数的位置

  $.Isotope.prototype._getCenteredMasonryColumns = function() {
    this.width = this.element.width();
    var parentWidth = this.element.parent().width();

    // i.e. options.masonry && options.masonry.columnWidth
    var colW = this.options.masonry && this.options.masonry.columnWidth ||
    // or use the size of the first item
    this.$filteredAtoms.outerWidth(true) ||
    // if there's no items, use size of container
    parentWidth;

    var cols = Math.floor( parentWidth / colW );
    cols = Math.max( cols, 1 );

    // i.e. this.masonry.cols = ....
    this.masonry.cols = cols;
    // i.e. this.masonry.columnWidth = ...
    this.masonry.columnWidth = colW;
  };

  $.Isotope.prototype._masonryReset = function() {
    // layout-specific props
    this.masonry = {};
    // FIXME shouldn't have to call this again
    this._getCenteredMasonryColumns();
    var i = this.masonry.cols;
    this.masonry.colYs = [];
    while (i--) {
      this.masonry.colYs.push( 0 );
    }
  };

  $.Isotope.prototype._masonryResizeChanged = function() {
    var prevColCount = this.masonry.cols;
    // get updated colCount
    this._getCenteredMasonryColumns();
    return ( this.masonry.cols !== prevColCount );
  };

  $.Isotope.prototype._masonryGetContainerSize = function() {
     var unusedCols = 0,
    i = this.masonry.cols;
    // count unused columns
    while ( --i ) {
      if ( this.masonry.colYs[i] !== 0 ) {
      break;
    }
    unusedCols++;
  }

   return {
      height : Math.max.apply( Math, this.masonry.colYs ),
      // fit container to columns that have been used;
      width : (this.masonry.cols - unusedCols) * this.masonry.columnWidth
    }
   };

有什么想法吗?

I can't find where i can put my own code on resize and reposition. I need to find where to insert the callback, this is the only bit i should be looking at and i just can't find where to insert the callback function on resize

  $.Isotope.prototype._getCenteredMasonryColumns = function() {
    this.width = this.element.width();
    var parentWidth = this.element.parent().width();

    // i.e. options.masonry && options.masonry.columnWidth
    var colW = this.options.masonry && this.options.masonry.columnWidth ||
    // or use the size of the first item
    this.$filteredAtoms.outerWidth(true) ||
    // if there's no items, use size of container
    parentWidth;

    var cols = Math.floor( parentWidth / colW );
    cols = Math.max( cols, 1 );

    // i.e. this.masonry.cols = ....
    this.masonry.cols = cols;
    // i.e. this.masonry.columnWidth = ...
    this.masonry.columnWidth = colW;
  };

  $.Isotope.prototype._masonryReset = function() {
    // layout-specific props
    this.masonry = {};
    // FIXME shouldn't have to call this again
    this._getCenteredMasonryColumns();
    var i = this.masonry.cols;
    this.masonry.colYs = [];
    while (i--) {
      this.masonry.colYs.push( 0 );
    }
  };

  $.Isotope.prototype._masonryResizeChanged = function() {
    var prevColCount = this.masonry.cols;
    // get updated colCount
    this._getCenteredMasonryColumns();
    return ( this.masonry.cols !== prevColCount );
  };

  $.Isotope.prototype._masonryGetContainerSize = function() {
     var unusedCols = 0,
    i = this.masonry.cols;
    // count unused columns
    while ( --i ) {
      if ( this.masonry.colYs[i] !== 0 ) {
      break;
    }
    unusedCols++;
  }

   return {
      height : Math.max.apply( Math, this.masonry.colYs ),
      // fit container to columns that have been used;
      width : (this.masonry.cols - unusedCols) * this.masonry.columnWidth
    }
   };

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

且行且努力 2025-01-10 09:51:40

解决方案是简单地执行 window.resize 并在其中应用计时器:

 var delay = (function(){
   var timer = 0;
   return function(callback, ms){
     clearTimeout (timer);
      timer = setTimeout(callback, ms);
   };
 })();

 $(window).resize(function() {
   delay(function(){
     if ($("#head").width() != $("#container").width()){
        var myLeft = $("#container").offset().left;
        var newWidth = $("#container").innerWidth();
        var myRight = $("#container").offset().left + $("#container").outerWidth();
        $("#head").animate({ width: newWidth, marginLeft: myLeft, marginRight: myRight }, "fast");
    }
  }, 800);
});

Solution was to simply do a window.resize an apply a timer in it:

 var delay = (function(){
   var timer = 0;
   return function(callback, ms){
     clearTimeout (timer);
      timer = setTimeout(callback, ms);
   };
 })();

 $(window).resize(function() {
   delay(function(){
     if ($("#head").width() != $("#container").width()){
        var myLeft = $("#container").offset().left;
        var newWidth = $("#container").innerWidth();
        var myRight = $("#container").offset().left + $("#container").outerWidth();
        $("#head").animate({ width: newWidth, marginLeft: myLeft, marginRight: myRight }, "fast");
    }
  }, 800);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文