Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor equal heights javascript function - dynamic items per row #28

Open
driesd opened this issue Nov 5, 2014 · 2 comments
Open
Assignees

Comments

@driesd
Copy link
Contributor

driesd commented Nov 5, 2014

Zie EANDIS:

$(window).load(function() {
var per_row = 4;
var $articles = $(".article");
var items = [];

      for (var i = 0; i <= $articles.length - 1; i += per_row) {
        items.push($articles.slice(i, (i + per_row)));
      }

      _.each(items, function(item) {
        if(item.length) {
          helper.equalheights(item, helper.highest(item));
        }
      });
    });
@driesd driesd self-assigned this Nov 5, 2014
@rob-bar
Copy link
Contributor

rob-bar commented Jan 9, 2015

Deze werkt op offset:

equalHeights: {
      attach: function () {
        $(window).load(function() {
          if ($(window).width() > 480) {
            var selectors = [
              ".selector1",
              ".selector2",
            ];

            var $items = $(selectors.join(", "));

            var items = _.groupBy($items, function(element, index, list) {
              return list.selector + $(element).offset().top;
            });

            items = _.values(items);

            _.each(items, function(item) {
              if(item.length) {
                helper.equalheights($(item), helper.highest($(item)));
              }
            });
          }
        });
      }
    },

@rob-bar
Copy link
Contributor

rob-bar commented Jan 15, 2015

beter de equal heights calc per rij doen en dan op offset checken, en niet enkel in het begin op offset checken

equalHeights: {
      attach: function () {
        $(window).load(function() {
          if ($(window).width() > 480) {
            var selectors = [
              "selector1",
              "selector2",
            ];

            var filter = function(element, index, list) {
              return $(list[0]).offset().top === $(element).offset().top;
            };

            _.each(selectors, function(selector) {
              var $selector = $(selector);

              while($selector.length > 0) {
                var el = _.filter($selector, filter);

                helper.equalheights($(el), helper.highest($(el)));
                $selector = _.difference($selector, el);
              }
            });
          }
        });
      }
    },

@rob-bar rob-bar added the Js label Jan 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants