Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save frozenspider/4bee3ccd970988d13541d40626900546 to your computer and use it in GitHub Desktop.
Save frozenspider/4bee3ccd970988d13541d40626900546 to your computer and use it in GitHub Desktop.
function debounce(func, wait, immediate) {
let timeout;
return function() {
let context = this, args = arguments;
let later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
let callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
const sizeDef = 45,
sizeMax = 25;
function rowWidth() {
let getRow = document.querySelector('.edited-row');
return getRow.offsetWidth;
}
function timelineQuantity() {
return parseInt(rowWidth() / sizeMax) - 1;
}
timelineQuantity();
const resizeVal = debounce(function() {
rowWidth();
timelineQuantity();
timeLineList(30);
}, 250);
function timeLineList(quantity) {
let maxSizeW = quantity * sizeDef;
if(maxSizeW > rowWidth()) {
let subtractionW = rowWidth() - maxSizeW,
shiftElm = Math.abs(subtractionW) / quantity,
elm = document.getElementsByClassName('edited-box');
for (let i = 0; i < elm.length; i++) {
console.log(elm[i] + ' ' + shiftElm);
elm[i + 1].style.marginLeft = -shiftElm + 'px';
}
}
}
window.addEventListener('resize', resizeVal);
@frozenspider
Copy link
Author

frozenspider commented Feb 13, 2018

function rescaleTimelineList(quantity) {
    let maxSizeW      = quantity * sizeDef,
        widthOvershot = maxSizeW - rowWidth();
    if (widthOvershot > 0) {
        let els        = document.getElementsByClassName('edited-box'),
            shiftPerEl = widthOvershot / quantity;
        for (let i = 1; i < els.length; i++) {
            console.log(els[i] + ' ' + shiftPerEl);
            els[i].style.marginLeft = (-shiftPerEl) + 'px';
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment