Created
June 20, 2013 14:28
-
-
Save wheresrhys/5823198 to your computer and use it in GitHub Desktop.
Adds outer/innerHeight/Width methods to Zepto Adapted from https://gist.github.com/alanhogan/3935463
This file contains 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($) { | |
// Add inner and outer width to zepto (adapted from https://gist.github.com/alanhogan/3935463) | |
var ioDim = function(dimension, includeBorder) { | |
return function (includeMargin) { | |
var sides, size, elem; | |
if (this) { | |
elem = this; | |
size = elem[dimension](); | |
sides = { | |
width: ["left", "right"], | |
height: ["top", "bottom"] | |
}; | |
sides[dimension].forEach(function(side) { | |
size += parseInt(elem.css("padding-" + side), 10); | |
if (includeBorder) { | |
size += parseInt(elem.css("border-" + side + "-width"), 10); | |
} | |
if (includeMargin) { | |
size += parseInt(elem.css("margin-" + side), 10); | |
} | |
}); | |
return size; | |
} else { | |
return null; | |
} | |
} | |
}; | |
["width", "height"].forEach(function(dimension) { | |
var Dimension = dimension.substr(0,1).toUpperCase() + dimension.substr(1); | |
$.fn["inner" + Dimension] = ioDim(dimension, false); | |
$.fn["outer" + Dimension] = ioDim(dimension, true); | |
}); | |
})(Zepto); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would I add support for box-sizing?