Skip to content

Instantly share code, notes, and snippets.

@m-arrieta-r
Created November 2, 2016 22:37
Show Gist options
  • Save m-arrieta-r/a277fc2a9b1e860572bebd65fc1061f6 to your computer and use it in GitHub Desktop.
Save m-arrieta-r/a277fc2a9b1e860572bebd65fc1061f6 to your computer and use it in GitHub Desktop.
isItOverflow
var getTotalMarginSize = function (element) {
var ml = parseInt(window.getComputedStyle(element).marginLeft);
var mr = parseInt(window.getComputedStyle(element).marginLeft);
return ml+mr;
};
var getChildrenSize = function(container) {
var children = container.children;
var sizeCounter = 0;
for(var i = 0; i < children.length; i++) {
var element = children[i];
sizeCounter += element.offsetWidth;
sizeCounter += getTotalMarginSize(element);
}
return sizeCounter;
};
var isItOverflow = function (container) {
var childrenSize = getChildrenSize(container);
return (container.offsetWidth > childrenSize);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment