Created
February 13, 2018 13:39
-
-
Save anonymous/78539b0bebbcff2dd4af136e67e19e3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment