Skip to content

Instantly share code, notes, and snippets.

@wesamly
Created March 17, 2020 11:06
Show Gist options
  • Select an option

  • Save wesamly/df0acd7c477a803fd6b9e35f95c99b47 to your computer and use it in GitHub Desktop.

Select an option

Save wesamly/df0acd7c477a803fd6b9e35f95c99b47 to your computer and use it in GitHub Desktop.

Revisions

  1. wesamly revised this gist Mar 17, 2020. 1 changed file with 4 additions and 9 deletions.
    13 changes: 4 additions & 9 deletions reset_same_top_elms_height.js
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,18 @@
    function resetSameTopElmsHeight(container, childSelector) {
    var cols, ph, pt, tempElms, i, ch, co, j, elm;
    var cols, ph, pt, tempElms, i, ch, co, j;

    cols = container.find(childSelector);
    ph = -1;
    pt = -1;
    tempElms = [];

    for (i in cols) {
    elm = cols[i];
    //console.log(elm)
    ch = elm.offsetHeight;//height();
    //co = $(cols[i]).offset();
    co = {top: elm.offsetTop - window.scrollY};
    $(elm).data('h_t', `${ch}`)
    //console.log(ch, co.top)
    ch = $(cols[i]).outerHeight();
    co = $(cols[i]).offset();
    if (pt != -1 && pt < co.top) {
    pt = co.top;
    for (j in tempElms) {
    $(tempElms[j]).height(ph)
    $(tempElms[j]).outerHeight(ph)
    }
    ph = -1
    tempElms = [];
  2. wesamly created this gist Mar 17, 2020.
    36 changes: 36 additions & 0 deletions reset_same_top_elms_height.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    function resetSameTopElmsHeight(container, childSelector) {
    var cols, ph, pt, tempElms, i, ch, co, j, elm;

    cols = container.find(childSelector);
    ph = -1;
    pt = -1;
    tempElms = [];

    for (i in cols) {
    elm = cols[i];
    //console.log(elm)
    ch = elm.offsetHeight;//height();
    //co = $(cols[i]).offset();
    co = {top: elm.offsetTop - window.scrollY};
    $(elm).data('h_t', `${ch}`)
    //console.log(ch, co.top)
    if (pt != -1 && pt < co.top) {
    pt = co.top;
    for (j in tempElms) {
    $(tempElms[j]).height(ph)
    }
    ph = -1
    tempElms = [];
    }

    tempElms.push(cols[i]);
    if (ph < ch) {
    ph = ch;
    }
    pt = co.top;
    }

    }

    //Example:
    resetSameTopElmsHeight($('.row'), '.col-sm-6');